The default PackageResolver for gwtoolbox has changed?

I spent the last 4 hours to understand why gwtoolbox is not injecting dependencies. It was a painful process; there was not any log, just a NullPointerException since there is nothing to inject in the container.

Anyway the problem occurred after upgrading gwtoolbox to 2.0-SNAPSHOT from 0.7. Finally I figured out that they changed default PackageResolver strategy in the new version. Before I wasn’t specifying any PackageResolver, meaning; I was relying on the default package resolver.

When they changed the default package resolver, my project was unable to discover components at compile time. Since no component was discovered at compile time, the container was empty at runtime and that was why there wasn’t any log.

As can be seen from the following code that the default package resolver is some kind of relaxed version of REGEXP.

public static Pattern resolvePattern(String expression, PackageResolver resolver) {
    switch (resolver) {

        case REGEXP:
            return Pattern.compile(expression);

        case PREFIX:
            String pattern = Pattern.quote(expression);
            return Pattern.compile(pattern + ".*");

        case SUFFIX:
            pattern = Pattern.quote(expression);
            return Pattern.compile(".*" + pattern);

        case DEFAULT:
            StringBuilder builder = new StringBuilder();
            int offset = 0;
            int i;
            while ((i = expression.indexOf('*', offset)) > -1) {
                String part = Pattern.quote(expression.substring(offset, i));
                builder.append(part);
                builder.append(".*");
                offset = i + 1;
            }
            if (offset < expression.length()) {
                builder.append(expression.substring(offset));
            }
            return Pattern.compile(builder.toString());

        default:
            throw new UnsupportedOperationException("Package resolver '" + resolver.name() + " is currently unsupported");
    }
}

Just be aware and do not spend 4 hours like me 🙂

Read More Post