static String resolveImageTagFromArgs(String imageTagString, Map<String, String> args) {
        String resolvedImageString = imageTagString;
        Set<String> foundArgs = findAllArgs(imageTagString);
        for (String foundArg : foundArgs) {
            // check if the arg referenced in imageTagString exists in the Dockerfile
            if (args.containsKey(foundArg)) {
                // resolve args that are referenced by this arg
                String arg = resolveImageTagFromArgs(args.get(foundArg), args);
                // replace the arg by its value
                resolvedImageString = resolvedImageString.replaceFirst(String.format("\\$\\{*%s\\}*", foundArg), arg);
            }
        }
        return resolvedImageString;
    }
Helper method for extractArgs(exposed for test)

@param argLines list of string arrays containing lines with words
@return map of parsed arguments
src/main/java/io/fabric8/maven/docker/util/DockerFileUtil.java