Example usage for com.google.gwt.core.ext ConfigurationProperty getValues

List of usage examples for com.google.gwt.core.ext ConfigurationProperty getValues

Introduction

In this page you can find the example usage for com.google.gwt.core.ext ConfigurationProperty getValues.

Prototype

List<String> getValues();

Source Link

Document

The values for the permutation currently being considered.

Usage

From source file:cc.alcina.framework.entity.gen.SimpleCssResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    try {/*from w  w  w  .ja v  a 2 s.com*/
        ConfigurationProperty cp = context.getGeneratorContext().getPropertyOracle()
                .getConfigurationProperty(IGNORE_DATA_URLS);
        logMissingUrlResources = !Boolean.valueOf(cp.getValues().get(0));
    } catch (BadPropertyValueException e1) {
        e1.printStackTrace();
    }
    URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);
    if (resources.length != 1) {
        logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null);
        throw new UnableToCompleteException();
    }
    URL resource = resources[0];
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + SimpleCssResource.class.getName() + "() {");
    sw.indent();
    if (!AbstractResourceGenerator.STRIP_COMMENTS) {
        // Convenience when examining the generated code.
        sw.println("// " + resource.toExternalForm());
    }
    sw.println("public String getText() {");
    sw.indent();
    String toWrite = Util.readURLAsString(resource);
    if (context.supportsDataUrls()) {
        try {
            toWrite = replaceWithDataUrls(context, toWrite);
        } catch (Exception e) {
            logger.log(Type.ERROR, "css data url gen", e);
            throw new UnableToCompleteException();
        }
    }
    if (toWrite.length() > MAX_STRING_CHUNK) {
        writeLongString(sw, toWrite);
    } else {
        sw.println("return \"" + Generator.escape(toWrite) + "\";");
    }
    sw.outdent();
    sw.println("}");
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");
    sw.outdent();
    sw.println("}");
    return sw.toString();
}

From source file:com.allen_sauer.gwt.log.rebind.LogMessageFormatterGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType userType;/*from w  w w. ja v  a 2  s  . c o m*/
    try {
        userType = typeOracle.getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "OOPS", e);
        throw new UnableToCompleteException();
    }
    String packageName = userType.getPackage().getName();
    String className = userType.getName();

    JClassType remoteService = typeOracle.findType(typeName);
    if (remoteService == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }

    if (remoteService.isInterface() == null) {
        logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            className + "Impl");
    composerFactory.addImplementedInterface(remoteService.getQualifiedSourceName());

    composerFactory.addImport(Date.class.getName());
    composerFactory.addImport(GWT.class.getName());
    composerFactory.addImport(LogUtil.class.getName());
    composerFactory.addImport(Duration.class.getName());

    PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl");
    if (pw != null) {
        SourceWriter sw = composerFactory.createSourceWriter(context, pw);

        PropertyOracle propertyOracle = context.getPropertyOracle();
        String logPattern;
        try {
            ConfigurationProperty logPatternProperty = propertyOracle
                    .getConfigurationProperty(PROPERTY_LOG_PATTERN);
            List<String> values = logPatternProperty.getValues();
            logPattern = values.get(0);
        } catch (BadPropertyValueException e) {
            logger.log(TreeLogger.ERROR, "Unable to find value for '" + PROPERTY_LOG_PATTERN + "'", e);
            throw new UnableToCompleteException();
        }

        sw.println();
        sw.println("private double BIG_BANG = Duration.currentTimeMillis();");

        sw.println();
        sw.println(
                "public String format(String logLevelText, String category, String message, Throwable throwable) {");
        sw.indent();
        sw.println("if (category == null) {");
        sw.indent();
        sw.println("category = \"<null category>\";");
        sw.outdent();
        sw.println("}");
        sw.println("if (message == null) {");
        sw.indent();
        sw.println("message = \"<null message>\";");
        sw.outdent();
        sw.println("}");
        sw.println(logPatternToCode(logPattern));
        sw.outdent();
        sw.println("}");

        sw.commit(logger);
    }
    return composerFactory.getCreatedClassName();
}

From source file:com.allen_sauer.gwt.log.rebind.RemoteLoggerConfigGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType userType;/*from  w  w w.  j av  a  2s. c  om*/
    try {
        userType = typeOracle.getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "OOPS", e);
        throw new UnableToCompleteException();
    }
    String packageName = userType.getPackage().getName();
    String className = userType.getName();

    JClassType remoteService = typeOracle.findType(typeName);
    if (remoteService == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }

    if (remoteService.isInterface() == null) {
        logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            className + "Impl");
    composerFactory.addImplementedInterface(remoteService.getQualifiedSourceName());

    PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl");
    if (pw != null) {
        SourceWriter sw = composerFactory.createSourceWriter(context, pw);

        PropertyOracle propertyOracle = context.getPropertyOracle();
        String logUrl;
        try {
            ConfigurationProperty logPatternProperty = propertyOracle
                    .getConfigurationProperty(PROPERTY_LOG_URL);
            List<String> values = logPatternProperty.getValues();
            logUrl = values.get(0);
        } catch (BadPropertyValueException e) {
            logger.log(TreeLogger.ERROR, "Unable to find value for '" + PROPERTY_LOG_URL + "'", e);
            throw new UnableToCompleteException();
        }

        sw.println();
        sw.println("public String serviceEntryPointUrl() {");
        sw.indent();

        if (logUrl == null) {
            sw.println("return null;");
        } else {
            sw.println("return \"" + logUrl.trim() + "\";");
        }

        sw.outdent();
        sw.println("}");

        sw.commit(logger);
    }
    return composerFactory.getCreatedClassName();
}

From source file:com.arcbees.gwtpolymer.rebind.velocity.ImportsVelocityGenerator.java

License:Apache License

@Override
protected void populateVelocityContext(VelocityContext velocityContext) throws UnableToCompleteException {
    ConfigurationProperty property = getGeneratorUtil().getConfigurationProperty(GWTPOLYMER_ELEMENTS);

    velocityContext.put("elements", new HashSet<>(property.getValues()));
}

From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private void gatherTypes(JType type, List<JType> types) {
    nesting++;/*from  w ww . jav  a2  s .  c  o m*/
    // 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("artemis.reflect.include");
        for (String s : prop.getValues())
            keep |= name.contains(s);
        prop = context.getPropertyOracle().getConfigurationProperty("artemis.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--;
}

From source file:com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator.java

License:Apache License

private AssetFilter getAssetFilter(GeneratorContext context) {
    ConfigurationProperty assetFilterClassProperty = null;
    try {// w  ww. j  a  v  a2s.  c  om
        assetFilterClassProperty = context.getPropertyOracle().getConfigurationProperty("gdx.assetfilterclass");
    } catch (BadPropertyValueException e) {
        return new DefaultAssetFilter();
    }
    if (assetFilterClassProperty.getValues().size() == 0) {
        return new DefaultAssetFilter();
    }
    String assetFilterClass = assetFilterClassProperty.getValues().get(0);
    if (assetFilterClass == null)
        return new DefaultAssetFilter();
    try {
        return (AssetFilter) Class.forName(assetFilterClass).newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Couldn't instantiate custom AssetFilter '" + assetFilterClass
                + "', make sure the class is public and has a public default constructor", e);
    }
}

From source file:com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator.java

License:Apache License

private String getAssetPath(GeneratorContext context) {
    ConfigurationProperty assetPathProperty = null;
    try {/*from www  .  j  a v  a2 s .  c o m*/
        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");
    }
}

From source file:com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator.java

License:Apache License

private String getAssetOutputPath(GeneratorContext context) {
    ConfigurationProperty assetPathProperty = null;
    try {/*from   w  ww. j  a  v a 2s  .  c o  m*/
        assetPathProperty = context.getPropertyOracle().getConfigurationProperty("gdx.assetoutputpath");
    } catch (BadPropertyValueException e) {
        return null;
    }
    if (assetPathProperty.getValues().size() == 0) {
        return null;
    }
    String paths = assetPathProperty.getValues().get(0);
    if (paths == null) {
        return null;
    } else {
        ArrayList<String> existingPaths = new ArrayList<String>();
        String[] tokens = paths.split(",");
        String path = null;
        for (String token : tokens) {
            if (new FileWrapper(token).exists() || new FileWrapper(token).mkdirs()) {
                path = token;
            }
        }
        if (path != null && !path.endsWith("/")) {
            path += "/";
        }
        return path;
    }
}

From source file:com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator.java

License:Apache License

private List<String> getClasspathFiles(GeneratorContext context) {
    List<String> classpathFiles = new ArrayList<String>();
    try {/*from ww  w .j a  v a  2s  . co m*/
        ConfigurationProperty prop = context.getPropertyOracle()
                .getConfigurationProperty("gdx.files.classpath");
        for (String value : prop.getValues()) {
            classpathFiles.add(value);
        }
    } catch (BadPropertyValueException e) {
        // Ignore
    }
    return classpathFiles;
}

From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

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);
        }/*  w  w w.  java  2s.c o m*/
    }

    // 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");
}