Search in sources :

Example 1 with BadPropertyValueException

use of com.google.gwt.core.ext.BadPropertyValueException in project libgdx by libgdx.

the class PreloaderBundleGenerator method getAssetPath.

private String getAssetPath(GeneratorContext context) {
    ConfigurationProperty assetPathProperty = null;
    try {
        assetPathProperty = context.getPropertyOracle().getConfigurationProperty("gdx.assetpath");
    } catch (BadPropertyValueException e) {
        throw new RuntimeException("No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file");
    }
    if (assetPathProperty.getValues().size() == 0) {
        throw new RuntimeException("No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file");
    }
    String paths = assetPathProperty.getValues().get(0);
    if (paths == null) {
        throw new RuntimeException("No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file");
    } else {
        ArrayList<String> existingPaths = new ArrayList<String>();
        String[] tokens = paths.split(",");
        for (String token : tokens) {
            System.out.println(token);
            if (new FileWrapper(token).exists() || new FileWrapper("../" + token).exists()) {
                return token;
            }
        }
        throw new RuntimeException("No valid gdx.assetpath defined. Fix <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> in your GWT projects gwt.xml file");
    }
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ArrayList(java.util.ArrayList) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException)

Example 2 with BadPropertyValueException

use of com.google.gwt.core.ext.BadPropertyValueException in project libgdx by libgdx.

the class ReflectionCacheSourceCreator method generateLookups.

private void generateLookups() {
    TypeOracle typeOracle = context.getTypeOracle();
    JPackage[] packages = typeOracle.getPackages();
    // gather all types from wanted packages
    for (JPackage p : packages) {
        for (JClassType t : p.getTypes()) {
            gatherTypes(t.getErasedType(), types);
        }
    }
    // gather all types from explicitly requested packages
    try {
        ConfigurationProperty prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.include");
        for (String s : prop.getValues()) {
            JClassType type = typeOracle.findType(s);
            if (type != null)
                gatherTypes(type.getErasedType(), types);
        }
    } catch (BadPropertyValueException e) {
    }
    gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types);
    // sort the types so the generated output will be stable between runs
    Collections.sort(types, new Comparator<JType>() {

        public int compare(JType o1, JType o2) {
            return o1.getQualifiedSourceName().compareTo(o2.getQualifiedSourceName());
        }
    });
    // generate Type lookup generator methods.
    for (JType t : types) {
        p(createTypeGenerator(t));
    }
    // generate reusable parameter objects
    parameterInitialization();
    // sort the stubs so the generated output will be stable between runs
    Collections.sort(setterGetterStubs, new Comparator<SetterGetterStub>() {

        @Override
        public int compare(SetterGetterStub o1, SetterGetterStub o2) {
            return new Integer(o1.setter).compareTo(o2.setter);
        }
    });
    // generate field setters/getters
    for (SetterGetterStub stub : setterGetterStubs) {
        String stubSource = generateSetterGetterStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }
    // sort the stubs so the generated output will be stable between runs
    Collections.sort(methodStubs, new Comparator<MethodStub>() {

        @Override
        public int compare(MethodStub o1, MethodStub o2) {
            return new Integer(o1.methodId).compareTo(o2.methodId);
        }
    });
    // generate methods
    for (MethodStub stub : methodStubs) {
        String stubSource = generateMethodStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }
    logger.log(Type.INFO, types.size() + " types reflected");
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException)

Example 3 with BadPropertyValueException

use of com.google.gwt.core.ext.BadPropertyValueException in project libgdx by libgdx.

the class ReflectionCacheSourceCreator method gatherTypes.

private void gatherTypes(JType type, List<JType> types) {
    nesting++;
    // came here from a type that has no super class
    if (type == null) {
        nesting--;
        return;
    }
    // package info
    if (type.getQualifiedSourceName().contains("-")) {
        nesting--;
        return;
    }
    // not visible
    if (!isVisible(type)) {
        nesting--;
        return;
    }
    // filter reflection scope based on configuration in gwt xml module
    boolean keep = false;
    String name = type.getQualifiedSourceName();
    try {
        ConfigurationProperty prop;
        keep |= !name.contains(".");
        prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.include");
        for (String s : prop.getValues()) keep |= name.contains(s);
        prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.exclude");
        for (String s : prop.getValues()) keep &= !name.equals(s);
    } catch (BadPropertyValueException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (!keep) {
        nesting--;
        return;
    }
    // already visited this type
    if (types.contains(type.getErasedType())) {
        nesting--;
        return;
    }
    types.add(type.getErasedType());
    out(type.getErasedType().getQualifiedSourceName(), nesting);
    if (type instanceof JPrimitiveType) {
        // nothing to do for a primitive type
        nesting--;
        return;
    } else {
        // gather fields
        JClassType c = (JClassType) type;
        JField[] fields = c.getFields();
        if (fields != null) {
            for (JField field : fields) {
                gatherTypes(field.getType().getErasedType(), types);
            }
        }
        // gather super types & interfaces
        gatherTypes(c.getSuperclass(), types);
        JClassType[] interfaces = c.getImplementedInterfaces();
        if (interfaces != null) {
            for (JClassType i : interfaces) {
                gatherTypes(i.getErasedType(), types);
            }
        }
        // gather method parameter & return types
        JMethod[] methods = c.getMethods();
        if (methods != null) {
            for (JMethod m : methods) {
                gatherTypes(m.getReturnType().getErasedType(), types);
                if (m.getParameterTypes() != null) {
                    for (JType p : m.getParameterTypes()) {
                        gatherTypes(p.getErasedType(), types);
                    }
                }
            }
        }
        // gather inner classes
        JClassType[] inner = c.getNestedTypes();
        if (inner != null) {
            for (JClassType i : inner) {
                gatherTypes(i.getErasedType(), types);
            }
        }
    }
    nesting--;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException)

Example 4 with BadPropertyValueException

use of com.google.gwt.core.ext.BadPropertyValueException in project gwtphonegap by dankurka.

the class PhoneGapLogThresholdGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    String level = "INFO";
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.threshold");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.threshold variable - defaulting to INFO");
        } else {
            level = values.get(0);
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.threshold variable - defaulting to INFO", e);
    }
    if ("INFO".equalsIgnoreCase(level)) {
        return BASE + ".Info";
    }
    if ("ALL".equalsIgnoreCase(level)) {
        return BASE + ".Info";
    }
    if ("FINEST".equalsIgnoreCase(level)) {
        return BASE + ".Finest";
    }
    if ("FINER".equalsIgnoreCase(level)) {
        return BASE + ".Finer";
    }
    if ("FINE".equalsIgnoreCase(level)) {
        return BASE + ".Fine";
    }
    if ("CONFIG".equalsIgnoreCase(level)) {
        return BASE + ".Config";
    }
    if ("WARNING".equalsIgnoreCase(level)) {
        return BASE + ".Warning";
    }
    if ("SEVERE".equalsIgnoreCase(level)) {
        return BASE + ".Severe";
    }
    if ("SEVERE".equalsIgnoreCase(level)) {
        return BASE + ".All";
    }
    logger.log(TreeLogger.WARN, "unkown value for phonegap.logging.threshold: '" + level + "' - defaulting to INFO");
    return BASE + ".Info";
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle)

Example 5 with BadPropertyValueException

use of com.google.gwt.core.ext.BadPropertyValueException in project gwtphonegap by dankurka.

the class PhoneGapLogValueGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    int value = 100;
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
        } else {
            String stringValue = values.get(0);
            try {
                value = Integer.parseInt(stringValue);
            } catch (Exception e) {
                logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
            }
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
    }
    JClassType classType = null;
    try {
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }
    String packageName = classType.getPackage().getName();
    String simpleName = classType.getSimpleSourceName() + "_" + value;
    String fullName = packageName + "." + simpleName;
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.addImplementedInterface(typeName);
    composer.addImport(typeName);
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return fullName;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.println("public int getMaxEntries() {");
    writer.println("return " + value + ";");
    writer.println("}");
    writer.commit(logger);
    return fullName;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Aggregations

BadPropertyValueException (com.google.gwt.core.ext.BadPropertyValueException)7 ConfigurationProperty (com.google.gwt.core.ext.ConfigurationProperty)7 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 PropertyOracle (com.google.gwt.core.ext.PropertyOracle)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)2 ArrayList (java.util.ArrayList)2 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)1 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)1 SourceWriter (com.google.gwt.user.rebind.SourceWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1