Search in sources :

Example 1 with SchemeSpecification

use of com.cloudbees.plugins.credentials.domains.SchemeSpecification in project blueocean-plugin by jenkinsci.

the class CredentialsUtils method generateDomainSpecifications.

public static List<DomainSpecification> generateDomainSpecifications(@Nullable String uriStr) {
    if (StringUtils.isBlank(uriStr)) {
        return Collections.emptyList();
    }
    List<DomainSpecification> domainSpecifications = new ArrayList<>();
    try {
        URI uri = new URI(uriStr);
        // XXX: UriRequirementBuilder.fromUri() maps "" path to "/", so need to take care of it here
        String path = uri.getRawPath() == null ? null : (uri.getRawPath().trim().isEmpty() ? "/" : uri.getRawPath());
        domainSpecifications.add(new PathSpecification(path, "", false));
        if (uri.getPort() != -1) {
            domainSpecifications.add(new HostnamePortSpecification(uri.getHost() + ":" + uri.getPort(), null));
        } else {
            domainSpecifications.add(new HostnameSpecification(uri.getHost(), null));
        }
        domainSpecifications.add(new SchemeSpecification(uri.getScheme()));
    } catch (URISyntaxException e) {
        //       for now, we are returning empty list to match with  URIRequirementBuilder.fromUri()
        return domainSpecifications;
    }
    return Collections.emptyList();
}
Also used : SchemeSpecification(com.cloudbees.plugins.credentials.domains.SchemeSpecification) HostnamePortSpecification(com.cloudbees.plugins.credentials.domains.HostnamePortSpecification) PathSpecification(com.cloudbees.plugins.credentials.domains.PathSpecification) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HostnameSpecification(com.cloudbees.plugins.credentials.domains.HostnameSpecification) DomainSpecification(com.cloudbees.plugins.credentials.domains.DomainSpecification)

Aggregations

DomainSpecification (com.cloudbees.plugins.credentials.domains.DomainSpecification)1 HostnamePortSpecification (com.cloudbees.plugins.credentials.domains.HostnamePortSpecification)1 HostnameSpecification (com.cloudbees.plugins.credentials.domains.HostnameSpecification)1 PathSpecification (com.cloudbees.plugins.credentials.domains.PathSpecification)1 SchemeSpecification (com.cloudbees.plugins.credentials.domains.SchemeSpecification)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1