class DefaultPluginPrefixResolver implements PluginPrefixResolver {
    private static final String REPOSITORY_CONTEXT = "plugin";

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final BuildPluginManager pluginManager;
    private final RepositorySystem repositorySystem;
    private final MetadataReader metadataReader;

    @Inject
    public DefaultPluginPrefixResolver(
            BuildPluginManager pluginManager, RepositorySystem repositorySystem, MetadataReader metadataReader) {
        this.pluginManager = pluginManager;
        this.repositorySystem = repositorySystem;
        this.metadataReader = metadataReader;
    }

    public PluginPrefixResult resolve(PluginPrefixRequest request) throws NoPluginFoundForPrefixException {<FILL_FUNCTION_BODY>}

    private PluginPrefixResult resolveFromProject(PluginPrefixRequest request) {
        PluginPrefixResult result = null;

        if (request.getPom() != null && request.getPom().getBuild() != null) {
            Build build = request.getPom().getBuild();

            result = resolveFromProject(request, build.getPlugins());

            if (result == null && build.getPluginManagement() != null) {
                result = resolveFromProject(request, build.getPluginManagement().getPlugins());
            }
        }

        return result;
    }

    private PluginPrefixResult resolveFromProject(PluginPrefixRequest request, List<Plugin> plugins) {
        for (Plugin plugin : plugins) {
            try {
                PluginDescriptor pluginDescriptor =
                        pluginManager.loadPlugin(plugin, request.getRepositories(), request.getRepositorySession());

                if (request.getPrefix().equals(pluginDescriptor.getGoalPrefix())) {
                    return new DefaultPluginPrefixResult(plugin);
                }
            } catch (Exception e) {
                if (logger.isDebugEnabled()) {
                    logger.warn("Failed to retrieve plugin descriptor for {}: {}", plugin.getId(), e.getMessage(), e);
                } else {
                    logger.warn("Failed to retrieve plugin descriptor for {}: {}", plugin.getId(), e.getMessage());
                }
            }
        }

        return null;
    }

    private PluginPrefixResult resolveFromRepository(PluginPrefixRequest request) {
        RequestTrace trace = RequestTrace.newChild(null, request);

        List<MetadataRequest> requests = new ArrayList<>();

        for (String pluginGroup : request.getPluginGroups()) {
            org.eclipse.aether.metadata.Metadata metadata =
                    new DefaultMetadata(pluginGroup, "maven-metadata.xml", DefaultMetadata.Nature.RELEASE_OR_SNAPSHOT);

            requests.add(new MetadataRequest(metadata, null, REPOSITORY_CONTEXT).setTrace(trace));

            for (RemoteRepository repository : request.getRepositories()) {
                requests.add(new MetadataRequest(metadata, repository, REPOSITORY_CONTEXT).setTrace(trace));
            }
        }

        // initial try, use locally cached metadata

        List<MetadataResult> results = repositorySystem.resolveMetadata(request.getRepositorySession(), requests);
        requests.clear();

        PluginPrefixResult result = processResults(request, trace, results, requests);

        if (result != null) {
            return result;
        }

        // second try, refetch all (possibly outdated) metadata that wasn't updated in the first attempt

        if (!request.getRepositorySession().isOffline() && !requests.isEmpty()) {
            DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(request.getRepositorySession());
            session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);

            results = repositorySystem.resolveMetadata(session, requests);

            return processResults(request, trace, results, null);
        }

        return null;
    }

    private PluginPrefixResult processResults(
            PluginPrefixRequest request,
            RequestTrace trace,
            List<MetadataResult> results,
            List<MetadataRequest> requests) {
        for (MetadataResult res : results) {
            org.eclipse.aether.metadata.Metadata metadata = res.getMetadata();

            if (metadata != null) {
                ArtifactRepository repository = res.getRequest().getRepository();
                if (repository == null) {
                    repository = request.getRepositorySession().getLocalRepository();
                }

                PluginPrefixResult result =
                        resolveFromRepository(request, trace, metadata.getGroupId(), metadata, repository);

                if (result != null) {
                    return result;
                }
            }

            if (requests != null && !res.isUpdated()) {
                requests.add(res.getRequest());
            }
        }

        return null;
    }

    private PluginPrefixResult resolveFromRepository(
            PluginPrefixRequest request,
            RequestTrace trace,
            String pluginGroup,
            org.eclipse.aether.metadata.Metadata metadata,
            ArtifactRepository repository) {
        if (metadata != null && metadata.getFile() != null && metadata.getFile().isFile()) {
            try {
                Map<String, ?> options = Collections.singletonMap(MetadataReader.IS_STRICT, Boolean.FALSE);

                Metadata pluginGroupMetadata = metadataReader.read(metadata.getFile(), options);

                List<org.apache.maven.artifact.repository.metadata.Plugin> plugins = pluginGroupMetadata.getPlugins();

                if (plugins != null) {
                    for (org.apache.maven.artifact.repository.metadata.Plugin plugin : plugins) {
                        if (request.getPrefix().equals(plugin.getPrefix())) {
                            return new DefaultPluginPrefixResult(pluginGroup, plugin.getArtifactId(), repository);
                        }
                    }
                }
            } catch (IOException e) {
                invalidMetadata(request.getRepositorySession(), trace, metadata, repository, e);
            }
        }

        return null;
    }

    private void invalidMetadata(
            RepositorySystemSession session,
            RequestTrace trace,
            org.eclipse.aether.metadata.Metadata metadata,
            ArtifactRepository repository,
            Exception exception) {
        RepositoryListener listener = session.getRepositoryListener();
        if (listener != null) {
            RepositoryEvent.Builder event = new RepositoryEvent.Builder(session, EventType.METADATA_INVALID);
            event.setTrace(trace);
            event.setMetadata(metadata);
            event.setException(exception);
            event.setRepository(repository);
            listener.metadataInvalid(event.build());
        }
    }
}

        logger.debug("Resolving plugin prefix {} from {}", request.getPrefix(), request.getPluginGroups());

        PluginPrefixResult result = resolveFromProject(request);

        if (result == null) {
            result = resolveFromRepository(request);

            if (result == null) {
                throw new NoPluginFoundForPrefixException(
                        request.getPrefix(),
                        request.getPluginGroups(),
                        request.getRepositorySession().getLocalRepository(),
                        request.getRepositories());
            } else {
                logger.debug(
                        "Resolved plugin prefix {} to {}:{} from repository {}",
                        request.getPrefix(),
                        result.getGroupId(),
                        result.getArtifactId(),
                        (result.getRepository() != null ? result.getRepository().getId() : "null"));
            }
        } else {
            logger.debug(
                    "Resolved plugin prefix {} to {}:{} from POM {}",
                    request.getPrefix(),
                    result.getGroupId(),
                    result.getArtifactId(),
                    request.getPom());
        }

        return result;
    
<no_super_class>