Java Code Examples for hudson.util.ListBoxModel#isEmpty()

The following examples show how to use hudson.util.ListBoxModel#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyScript.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns all registered Groovy parsers. These are packed into a {@link ListBoxModel} in order to show them in
 * the list box of the config.jelly view part.
 *
 * @return the model of the list box
 */
@SuppressWarnings("unused") // Called from config.jelly
public ListBoxModel doFillParserIdItems() {
    ListBoxModel options = ParserConfiguration.getInstance().asListBoxModel();
    if (options.isEmpty()) {
        return options.add(Messages.Warnings_Groovy_NoParsersDefined());
    }
    return options;
}
 
Example 2
Source File: GiteaSCMSource.java    From gitea-plugin with MIT License 4 votes vote down vote up
public ListBoxModel doFillRepositoryItems(@AncestorInPath SCMSourceOwner context,
                                          @QueryParameter String serverUrl,
                                          @QueryParameter String credentialsId,
                                          @QueryParameter String repoOwner,
                                          @QueryParameter String repository) throws IOException,
        InterruptedException {
    ListBoxModel result = new ListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.add(repository);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.add(repository);
            return result;
        }
    }
    if (StringUtils.isBlank(repoOwner)) {
        result.add(repository);
        return result;
    }
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        // you can only get the list for registered servers
        result.add(repository);
        return result;
    }
    StandardCredentials credentials = CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(
                    StandardCredentials.class,
                    context,
                    context instanceof Queue.Task
                            ? ((Queue.Task) context).getDefaultAuthentication()
                            : ACL.SYSTEM,
                    URIRequirementBuilder.fromUri(serverUrl).build()
            ),
            CredentialsMatchers.allOf(
                    AuthenticationTokens.matcher(GiteaAuth.class),
                    CredentialsMatchers.withId(credentialsId)
            )
    );
    try (GiteaConnection c = Gitea.server(serverUrl)
            .as(AuthenticationTokens.convert(GiteaAuth.class, credentials))
            .open()) {
        GiteaOwner owner = c.fetchOwner(repoOwner);
        List<GiteaRepository> repositories = c.fetchRepositories(owner);
        for (GiteaRepository r : repositories) {
            result.add(r.getName());
        }
        return result;
    } catch (IOException e) {
        // TODO once enhanced <f:select> that can handle error responses, just throw
        LOGGER.log(Level.FINE, "Could not populate repositories", e);
        if (result.isEmpty()) {
            result.add(repository);
        }
        return result;
    }
}