Search in sources :

Example 1 with DownloadScheme

use of com.google.gerrit.extensions.config.DownloadScheme in project gerrit by GerritCodeReview.

the class GetServerInfo method getDownloadInfo.

private DownloadInfo getDownloadInfo(DynamicMap<DownloadScheme> downloadSchemes, DynamicMap<DownloadCommand> downloadCommands, DynamicMap<CloneCommand> cloneCommands, AllowedFormats archiveFormats) {
    DownloadInfo info = new DownloadInfo();
    info.schemes = new HashMap<>();
    for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
        DownloadScheme scheme = e.getProvider().get();
        if (scheme.isEnabled() && scheme.getUrl("${project}") != null) {
            info.schemes.put(e.getExportName(), getDownloadSchemeInfo(scheme, downloadCommands, cloneCommands));
        }
    }
    info.archives = archiveFormats.getAllowed().stream().map(ArchiveFormat::getShortName).collect(toList());
    return info;
}
Also used : DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ArchiveFormat(com.google.gerrit.server.change.ArchiveFormat) DownloadInfo(com.google.gerrit.extensions.common.DownloadInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme)

Example 2 with DownloadScheme

use of com.google.gerrit.extensions.config.DownloadScheme in project gerrit by GerritCodeReview.

the class ChangeJson method makeFetchMap.

private Map<String, FetchInfo> makeFetchMap(ChangeControl ctl, PatchSet in) throws OrmException {
    Map<String, FetchInfo> r = new LinkedHashMap<>();
    for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
        String schemeName = e.getExportName();
        DownloadScheme scheme = e.getProvider().get();
        if (!scheme.isEnabled() || (scheme.isAuthRequired() && !userProvider.get().isIdentifiedUser())) {
            continue;
        }
        if (!scheme.isAuthSupported() && !ctl.forUser(anonymous).isPatchVisible(in, db.get())) {
            continue;
        }
        String projectName = ctl.getProject().getNameKey().get();
        String url = scheme.getUrl(projectName);
        String refName = in.getRefName();
        FetchInfo fetchInfo = new FetchInfo(url, refName);
        r.put(schemeName, fetchInfo);
        if (has(DOWNLOAD_COMMANDS)) {
            populateFetchMap(scheme, downloadCommands, projectName, refName, fetchInfo);
        }
    }
    return r;
}
Also used : DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) FetchInfo(com.google.gerrit.extensions.common.FetchInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DownloadScheme

use of com.google.gerrit.extensions.config.DownloadScheme in project gerrit by GerritCodeReview.

the class ChangeEditJson method fillFetchMap.

private Map<String, FetchInfo> fillFetchMap(ChangeEdit edit) {
    Map<String, FetchInfo> r = new LinkedHashMap<>();
    for (Extension<DownloadScheme> e : downloadSchemes) {
        String schemeName = e.getExportName();
        DownloadScheme scheme = e.getProvider().get();
        if (!scheme.isEnabled() || (scheme.isAuthRequired() && !userProvider.get().isIdentifiedUser())) {
            continue;
        }
        // No fluff, just stuff
        if (!scheme.isAuthSupported()) {
            continue;
        }
        String projectName = edit.getChange().getProject().get();
        String refName = edit.getRefName();
        FetchInfo fetchInfo = new FetchInfo(scheme.getUrl(projectName), refName);
        r.put(schemeName, fetchInfo);
        DownloadCommandsJson.populateFetchMap(scheme, downloadCommands, projectName, refName, fetchInfo);
    }
    return r;
}
Also used : FetchInfo(com.google.gerrit.extensions.common.FetchInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DownloadScheme

use of com.google.gerrit.extensions.config.DownloadScheme in project gerrit by GerritCodeReview.

the class RevisionJson method makeFetchMap.

private Map<String, FetchInfo> makeFetchMap(ChangeData cd, PatchSet in) throws PermissionBackendException {
    Map<String, FetchInfo> r = new LinkedHashMap<>();
    for (Extension<DownloadScheme> e : downloadSchemes) {
        String schemeName = e.getExportName();
        DownloadScheme scheme = e.getProvider().get();
        if (!scheme.isEnabled() || (scheme.isAuthRequired() && !userProvider.get().isIdentifiedUser())) {
            continue;
        }
        if (!scheme.isAuthSupported() && !isWorldReadable(cd)) {
            continue;
        }
        String projectName = cd.project().get();
        String url = scheme.getUrl(projectName);
        String refName = in.refName();
        FetchInfo fetchInfo = new FetchInfo(url, refName);
        r.put(schemeName, fetchInfo);
        if (has(DOWNLOAD_COMMANDS)) {
            DownloadCommandsJson.populateFetchMap(scheme, downloadCommands, projectName, refName, fetchInfo);
        }
    }
    return r;
}
Also used : FetchInfo(com.google.gerrit.extensions.common.FetchInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with DownloadScheme

use of com.google.gerrit.extensions.config.DownloadScheme in project gerrit by GerritCodeReview.

the class GetServerInfo method getDownloadInfo.

private DownloadInfo getDownloadInfo() {
    DownloadInfo info = new DownloadInfo();
    info.schemes = new HashMap<>();
    downloadSchemes.runEach(extension -> {
        DownloadScheme scheme = extension.get();
        if (scheme.isEnabled() && scheme.getUrl("${project}") != null) {
            info.schemes.put(extension.getExportName(), getDownloadSchemeInfo(scheme));
        }
    });
    info.archives = archiveFormats.getAllowed().stream().map(ArchiveFormatInternal::getShortName).collect(toList());
    return info;
}
Also used : DownloadInfo(com.google.gerrit.extensions.common.DownloadInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme) ArchiveFormatInternal(com.google.gerrit.server.change.ArchiveFormatInternal)

Aggregations

DownloadScheme (com.google.gerrit.extensions.config.DownloadScheme)5 FetchInfo (com.google.gerrit.extensions.common.FetchInfo)3 LinkedHashMap (java.util.LinkedHashMap)3 DownloadInfo (com.google.gerrit.extensions.common.DownloadInfo)2 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)2 ArchiveFormat (com.google.gerrit.server.change.ArchiveFormat)1 ArchiveFormatInternal (com.google.gerrit.server.change.ArchiveFormatInternal)1