protected VelocityContext buildVelocityContext()

in src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java [781:826]


    protected VelocityContext buildVelocityContext(Map<String, Object> properties) {
        // the following properties are expensive to calculate, so we provide them lazily
        VelocityContext context = new VelocityContext(properties) {
            @Override
            public Object internalGet(String key) {
                Object result = super.internalGet(key);
                if (result == null && key != null && key.startsWith(KEY_PROJECTS) && containsKey(key)) {
                    // calculate and put projects* properties
                    List<MavenProject> projects = getProjects();
                    put(KEY_PROJECTS, projects);
                    put(KEY_PROJECTS_ORGS, getProjectsSortedByOrganization(projects));
                    return super.internalGet(key);
                }
                return result;
            }
        };
        // to have a consistent getKeys()/containsKey() behaviour, keys must be present from the start
        context.put(KEY_PROJECTS, null);
        context.put(KEY_PROJECTS_ORGS, null);
        // the following properties are cheap to calculate, so we provide them eagerly

        // Reproducible Builds: try to use reproducible output timestamp
        MavenArchiver archiver = new MavenArchiver();
        Date outputDate = archiver.parseOutputTimestamp(outputTimestamp);

        String inceptionYear = project.getInceptionYear();
        String year = new SimpleDateFormat("yyyy").format((outputDate == null) ? new Date() : outputDate);

        if (inceptionYear == null || inceptionYear.isEmpty()) {
            if (getLog().isDebugEnabled()) {
                getLog().debug("inceptionYear not specified, defaulting to " + year);
            }

            inceptionYear = year;
        }
        context.put("project", project);
        context.put("presentYear", year);
        context.put("locator", locator);

        if (inceptionYear.equals(year)) {
            context.put("projectTimespan", year);
        } else {
            context.put("projectTimespan", inceptionYear + "-" + year);
        }
        return context;
    }