Search in sources :

Example 1 with Uploader

use of org.jreleaser.model.Uploader in project jreleaser by jreleaser.

the class Uploaders method upload.

public static void upload(JReleaserContext context) {
    Upload upload = context.getModel().getUpload();
    if (!upload.isEnabled()) {
        context.getLogger().info(RB.$("uploaders.not.enabled"));
        return;
    }
    if (!context.getIncludedUploaderTypes().isEmpty()) {
        for (String uploaderType : context.getIncludedUploaderTypes()) {
            // check if the uploaderType is valid
            if (!Upload.supportedUploaders().contains(uploaderType)) {
                context.getLogger().warn(RB.$("ERROR_unsupported_uploader", uploaderType));
                continue;
            }
            Map<String, Uploader> uploaders = upload.findUploadersByType(uploaderType);
            if (uploaders.isEmpty()) {
                context.getLogger().debug(RB.$("uploaders.no.match"), uploaderType);
                return;
            }
            if (!context.getIncludedUploaderNames().isEmpty()) {
                for (String uploaderName : context.getIncludedUploaderNames()) {
                    if (!uploaders.containsKey(uploaderName)) {
                        context.getLogger().warn(RB.$("uploaders.uploader.not.configured"), uploaderType, uploaderName);
                        continue;
                    }
                    Uploader uploader = uploaders.get(uploaderName);
                    if (!uploader.isEnabled()) {
                        context.getLogger().info(RB.$("uploaders.uploader.disabled"), uploaderType, uploaderName);
                        continue;
                    }
                    context.getLogger().info(RB.$("uploaders.upload.with"), uploaderType, uploaderName);
                    upload(context, uploader);
                }
            } else {
                context.getLogger().info(RB.$("uploaders.upload.all.artifacts.with"), uploaderType);
                uploaders.values().forEach(uploader -> upload(context, uploader));
            }
        }
    } else if (!context.getIncludedUploaderNames().isEmpty()) {
        for (String uploaderName : context.getIncludedUploaderNames()) {
            List<Uploader> filteredUploaders = upload.findAllActiveUploaders().stream().filter(a -> uploaderName.equals(a.getName())).collect(toList());
            if (!filteredUploaders.isEmpty()) {
                context.getLogger().info(RB.$("uploaders.upload.all.artifacts.to"), uploaderName);
                filteredUploaders.forEach(uploader -> upload(context, uploader));
            } else {
                context.getLogger().warn(RB.$("uploaders.uploader.not.configured2"), uploaderName);
            }
        }
    } else {
        context.getLogger().info(RB.$("uploaders.upload.all.artifacts"));
        for (Uploader uploader : upload.findAllActiveUploaders()) {
            String uploaderType = uploader.getType();
            String uploaderName = uploader.getName();
            if (context.getExcludedUploaderTypes().contains(uploaderType) || context.getExcludedUploaderNames().contains(uploaderName)) {
                context.getLogger().info(RB.$("uploaders.uploader.excluded"), uploaderType, uploaderName);
                continue;
            }
            upload(context, uploader);
        }
    }
}
Also used : List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) UploadException(org.jreleaser.model.uploader.spi.UploadException) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) JReleaserException(org.jreleaser.util.JReleaserException) Uploader(org.jreleaser.model.Uploader) RB(org.jreleaser.bundle.RB) Upload(org.jreleaser.model.Upload) Upload(org.jreleaser.model.Upload) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Uploader(org.jreleaser.model.Uploader)

Example 2 with Uploader

use of org.jreleaser.model.Uploader in project jreleaser by jreleaser.

the class Artifacts method resolveDownloadUrlFromUploader.

private static String resolveDownloadUrlFromUploader(JReleaserContext context, ExtraProperties props, Artifact artifact) {
    Upload upload = context.getModel().getUpload();
    String coords = props.getExtraProperty(DOWNLOAD_URL_FROM_KEY);
    if (isBlank(coords)) {
        // search for "<uploaderType><uploaderName>Path"
        for (Uploader up : upload.findAllActiveUploaders()) {
            List<String> keys = up.resolveSkipKeys();
            String key = up.getType() + capitalize(up.getName()) + "Path";
            if (artifact.getExtraProperties().containsKey(key) && !isSkip(props, keys)) {
                return up.getResolvedDownloadUrl(context, artifact);
            }
        }
        return null;
    }
    String[] parts = coords.split(":");
    if (parts.length != 2)
        return null;
    Optional<? extends Uploader> uploader = upload.getActiveUploader(parts[0], parts[1]);
    if (uploader.isPresent()) {
        List<String> keys = uploader.get().resolveSkipKeys();
        if (!isSkip(props, keys)) {
            return uploader.get().getResolvedDownloadUrl(context, artifact);
        }
    } else {
        // search for "<uploaderType><uploaderName>Path"
        for (Uploader up : upload.findAllActiveUploaders()) {
            List<String> keys = up.resolveSkipKeys();
            String key = up.getType() + capitalize(up.getName()) + "Path";
            if (artifact.getExtraProperties().containsKey(key) && !isSkip(props, keys)) {
                return up.getResolvedDownloadUrl(context, artifact);
            }
        }
    }
    return null;
}
Also used : Upload(org.jreleaser.model.Upload) Uploader(org.jreleaser.model.Uploader)

Aggregations

Upload (org.jreleaser.model.Upload)2 Uploader (org.jreleaser.model.Uploader)2 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 RB (org.jreleaser.bundle.RB)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 UploadException (org.jreleaser.model.uploader.spi.UploadException)1 JReleaserException (org.jreleaser.util.JReleaserException)1