class VersionsMetadataGenerator implements MetadataGenerator {

    private final Map<Object, VersionsMetadata> versions;

    private final Map<Object, VersionsMetadata> processedVersions;

    private final Date timestamp;

    VersionsMetadataGenerator(RepositorySystemSession session, InstallRequest request) {
        this(session, request.getMetadata());
    }

    VersionsMetadataGenerator(RepositorySystemSession session, DeployRequest request) {
        this(session, request.getMetadata());
    }

    private VersionsMetadataGenerator(RepositorySystemSession session, Collection<? extends Metadata> metadatas) {
        versions = new LinkedHashMap<>();
        processedVersions = new LinkedHashMap<>();
        timestamp = (Date) ConfigUtils.getObject(session, new Date(), "maven.startTime");

        /*
         * NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which
         * processes one artifact at a time and hence cannot associate the artifacts from the same project to use the
         * same version index. Allowing the caller to pass in metadata from a previous deployment allows to re-establish
         * the association between the artifacts of the same project.
         */
        for (Iterator<? extends Metadata> it = metadatas.iterator(); it.hasNext(); ) {
            Metadata metadata = it.next();
            if (metadata instanceof VersionsMetadata) {
                it.remove();
                VersionsMetadata versionsMetadata = (VersionsMetadata) metadata;
                processedVersions.put(versionsMetadata.getKey(), versionsMetadata);
            }
        }
    }

    @Override
    public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
        return Collections.emptyList();
    }

    @Override
    public Artifact transformArtifact(Artifact artifact) {
        return artifact;
    }

    @Override
    public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {<FILL_FUNCTION_BODY>}
}

        for (Artifact artifact : artifacts) {
            Object key = VersionsMetadata.getKey(artifact);
            if (processedVersions.get(key) == null) {
                VersionsMetadata versionsMetadata = versions.get(key);
                if (versionsMetadata == null) {
                    versionsMetadata = new VersionsMetadata(artifact, timestamp);
                    versions.put(key, versionsMetadata);
                }
            }
        }

        return versions.values();
    
<no_super_class>