@Override
    public String resolveVariable(String key) {
        if (key.startsWith("project.")) {
            return resolveVariable(key.substring("project.".length()));
        } else if (key.startsWith("pom.")) {
            return resolveVariable(key.substring("pom.".length()));
        } else if (key.startsWith("parent.")) {
            if (parent == null)
                return null;
            return parent.resolveVariable(key.substring("parent.".length()));
        } else if (key.startsWith("env.")) {
            return System.getenv(key.substring("env.".length()));
        }
        if ("packaging".equals(key))
            key = "type";
        if (Arrays.binarySearch(ATTRIBUTE_NAMES, key) >= 0) {
            try {
                Field field = getClass().getDeclaredField(key);
                return String.valueOf(field.get(this));
            } catch (Exception e) {
                return null;
            }
        } else if (System.getProperty(key) != null) {
            return System.getProperty(key);
        } else if (properties != null) {
            String property = properties.getProperty(key);
            if (property == null && parent != null) {
                property = parent.resolveVariable(key);
            }
            return property;
        } else {
            // delegate parent to resolve it
            if (parent == null) return null;
            return parent.resolveVariable(key);
        }
    }
@Override
    public String resolveVariable(String key) {
        if (key.startsWith("project.")) {
            return resolveVariable(key.substring("project.".length()));
        } else if (key.startsWith("pom.")) {
            return resolveVariable(key.substring("pom.".length()));
        } else if (key.startsWith("parent.")) {
            if (parent == null)
                return null;
            return parent.resolveVariable(key.substring("parent.".length()));
        } else if (key.startsWith("env.")) {
            return System.getenv(key.substring("env.".length()));
        }
        if ("packaging".equals(key))
            key = "type";
        if (Arrays.binarySearch(ATTRIBUTE_NAMES, key) >= 0) {
            try {
                Field field = getClass().getDeclaredField(key);
                return String.valueOf(field.get(this));
            } catch (Exception e) {
                return null;
            }
        } else if (System.getProperty(key) != null) {
            return System.getProperty(key);
        } else if (properties != null) {
            String property = properties.getProperty(key);
            if (property == null && parent != null) {
                property = parent.resolveVariable(key);
            }
            return property;
        } else {
            
            if (parent == null) return null;
            return parent.resolveVariable(key);
        }
    }
@ Override public String resolveVariable ( String key ) { if ( key . startsWith ( "project." ) ) { return resolveVariable ( key . substring ( "project." . length ( ) ) ) ; } else if ( key . startsWith ( "pom." ) ) { return resolveVariable ( key . substring ( "pom." . length ( ) ) ) ; } else if ( key . startsWith ( "parent." ) ) { if ( parent == null ) return null ; return parent . resolveVariable ( key . substring ( "parent." . length ( ) ) ) ; } else if ( key . startsWith ( "env." ) ) { return System . getenv ( key . substring ( "env." . length ( ) ) ) ; } if ( "packaging" . equals ( key ) ) key = "type" ; if ( Arrays . binarySearch ( ATTRIBUTE_NAMES , key ) >= 0 ) { try { Field field = getClass ( ) . getDeclaredField ( key ) ; return String . valueOf ( field . get ( this ) ) ; } catch ( Exception e ) { return null ; } } else if ( System . getProperty ( key ) != null ) { return System . getProperty ( key ) ; } else if ( properties != null ) { String property = properties . getProperty ( key ) ; if ( property == null && parent != null ) { property = parent . resolveVariable ( key ) ; } return property ; } else { // delegate parent to resolve it if ( parent == null ) return null ; return parent . resolveVariable ( key ) ; } }
其实如果以当前project为this，把env, system作为上下文， 通过对象图的方式提供变量索引，实现起来更好
其实如果以当前project为this，把env system作为上下文， 通过对象图的方式提供变量索引，实现起来更好