Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:org.jboss.tools.openshift.internal.common.ui.explorer.BaseExplorerLabelProvider.java

@Override
public StyledString getStyledText(Object element) {
    if (element instanceof BaseExplorerContentProvider.LoadingStub) {
        return new StyledString("Loading...");
    }//from w w w.j av a2 s. com
    if (element instanceof Exception) {
        Exception exception = (Exception) element;
        return new StyledString(
                StringUtils.defaultIfBlank(exception.getMessage(), exception.getClass().getName()));
    }
    return new StyledString(element.toString());
}

From source file:org.jboss.tools.openshift.internal.core.models.PortSpecAdapter.java

/**
 * //from ww  w.  j  a  va2s  .  c  o  m
 * @param spec A string in the form of "port/protocol"
 * @throws IllegalArgumentException if the port info can not be determined from the spec
 */
public PortSpecAdapter(String spec) {
    String[] parts = StringUtils.defaultIfBlank(spec, "").split("/");
    if (parts.length != 2) {
        throw new IllegalArgumentException(NLS.bind("Unable to determine port info from spec {0}", spec));
    }
    port = Integer.valueOf(parts[0]);
    protocol = parts[1].toUpperCase();
    name = getName(port, protocol);
}

From source file:org.jboss.tools.openshift.internal.ui.portforwading.PortForwardingWizardPage.java

protected TableViewer createTable(Composite tableContainer, DataBindingContext dbc) {
    Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setLinesVisible(true);//from   w  ww.  j ava2s.c  o m
    table.setHeaderVisible(true);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableContainer.setLayout(tableLayout);
    TableViewer viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());

    createTableColumn("Name", 1, new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            IPortForwardable.PortPair port = (IPortForwardable.PortPair) cell.getElement();
            cell.setText(StringUtils.defaultIfBlank(port.getName(), ""));
        }

    }, viewer, tableLayout);

    createTableColumn("Local Port", 2, new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            IPortForwardable.PortPair port = (IPortForwardable.PortPair) cell.getElement();
            cell.setText(Integer.toString(port.getLocalPort()));
        }
    }, viewer, tableLayout);

    createTableColumn("Remote Port", 2, new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            IPortForwardable.PortPair port = (IPortForwardable.PortPair) cell.getElement();
            cell.setText(Integer.toString(port.getRemotePort()));
        }
    }, viewer, tableLayout);

    createTableColumn("Status", 1, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final boolean started = wizardModel.getPortForwarding();
            cell.setText(started ? "Started" : "Stopped");
        }
    }, viewer, tableLayout);

    IObservableValue forwardablePortsModelObservable = BeanProperties
            .value(PortForwardingWizardModel.PROPERTY_FORWARDABLE_PORTS).observe(wizardModel);

    final ForwardablePortListValidator validator = new ForwardablePortListValidator(
            forwardablePortsModelObservable);
    dbc.addValidationStatusProvider(validator);

    viewer.setInput(wizardModel.getForwardablePorts());
    //      
    return viewer;
}

From source file:org.jboss.tools.openshift.internal.ui.wizard.deployimage.DeployImageWizardModel.java

protected IDockerImageMetadata lookupImageMetadata() {
    if (StringUtils.isBlank(this.imageName)) {
        return null;
    }/*from w  w  w .j  av a2  s . c  om*/
    final DockerImageURI imageURI = new DockerImageURI(this.imageName);
    final String repo = imageURI.getUriWithoutTag();
    final String tag = StringUtils.defaultIfBlank(imageURI.getTag(), "latest");

    if (dockerConnection != null && DockerImageUtils.hasImage(dockerConnection, repo, tag)) {
        final IDockerImageInfo info = dockerConnection.getImageInfo(this.imageName);
        if (info == null) {
            return null;
        }
        return new DockerConfigMetaData(info);
    } else if (this.project != null) {
        return DockerImageUtils.lookupImageMetadata(project, imageURI);
    }
    return null;
}

From source file:org.jboss.tools.openshift.internal.ui.wizard.deployimage.PortSpecAdapter.java

/**
 * //from w ww . j  a va 2s  .  c o m
 * @param spec A string in the form of "port/protocol"
 * @throws IllegalArgumentException if the port info can not be determined from the spec
 */
public PortSpecAdapter(String spec) {
    String[] parts = StringUtils.defaultIfBlank(spec, "").split("/");
    if (parts.length != 2) {
        throw new IllegalArgumentException(NLS.bind("Unable to determine port info from spec {0}", spec));
    }
    port = Integer.valueOf(parts[0]);
    protocol = parts[1].toUpperCase();
    name = NLS.bind("{0}-{1}", port, protocol.toLowerCase());
}

From source file:org.jenkinsci.plugins.githubissues.IssueCreator.java

/**
 * Creates a GitHub issue for a failing build
 * @param run Build that failed//w ww  . j a  v  a 2s  .  co  m
 * @param jobConfig the job config of the GitHubIssueNotifier
 * @param repo Repository to create the issue in
 * @param listener Build listener
 * @param workspace Build workspace
 * @return The issue that was created
 * @throws IOException when an unexpected problem occurs
 */
public static GHIssue createIssue(Run<?, ?> run, GitHubIssueNotifier jobConfig, GHRepository repo,
        TaskListener listener, FilePath workspace) throws IOException {
    final GitHubIssueNotifier.DescriptorImpl globalConfig = jobConfig.getDescriptor();

    String title = StringUtils.defaultIfBlank(jobConfig.getIssueTitle(), globalConfig.getIssueTitle());
    String body = StringUtils.defaultIfBlank(jobConfig.getIssueBody(), globalConfig.getIssueBody());
    String label = StringUtils.defaultIfBlank(jobConfig.getIssueLabel(), globalConfig.getIssueLabel());

    GHIssueBuilder issueBuilder = repo.createIssue(formatText(title, run, listener, workspace))
            .body(formatText(body, run, listener, workspace));

    GHIssue issue = issueBuilder.create();

    if (label != null && !label.isEmpty()) {
        issue.setLabels(label.split(",| "));
    }
    return issue;
}

From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java

/**
 * Constructor.//from ww w  .j a va  2 s  .  c o m
 *
 * @param source   the {@link GitHubSCMSource}.
 * @param head     the {@link SCMHead}
 * @param revision the (optional) {@link SCMRevision}
 */
public GitHubSCMBuilder(@NonNull GitHubSCMSource source, @NonNull SCMHead head,
        @CheckForNull SCMRevision revision) {
    super(head, revision, /*dummy value*/guessRemote(source), source.getCredentialsId());
    this.context = source.getOwner();
    apiUri = StringUtils.defaultIfBlank(source.getApiUri(), GitHubServerConfig.GITHUB_URL);
    repoOwner = source.getRepoOwner();
    repository = source.getRepository();
    repositoryUrl = source.getRepositoryUrl();
    // now configure the ref specs
    withoutRefSpecs();
    String repoUrl;
    if (head instanceof PullRequestSCMHead) {
        PullRequestSCMHead h = (PullRequestSCMHead) head;
        withRefSpec("+refs/pull/" + h.getId() + "/head:refs/remotes/@{remote}/" + head.getName());
        repoUrl = repositoryUrl(h.getSourceOwner(), h.getSourceRepo());
    } else if (head instanceof TagSCMHead) {
        withRefSpec("+refs/tags/" + head.getName() + ":refs/tags/" + head.getName());
        repoUrl = repositoryUrl(repoOwner, repository);
    } else {
        withRefSpec("+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName());
        repoUrl = repositoryUrl(repoOwner, repository);
    }
    // pre-configure the browser
    if (repoUrl != null) {
        withBrowser(new GithubWeb(repoUrl));
    }
}

From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.java

@NonNull
@Override
protected String id() {
    return StringUtils.defaultIfBlank(apiUri, GitHubSCMSource.GITHUB_URL) + "::" + repoOwner;
}

From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.java

/**
 * {@inheritDoc}/*from   ww  w.  j  a v a 2 s  .c  o m*/
 */
@NonNull
@Override
public List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner, @CheckForNull SCMNavigatorEvent event,
        @NonNull TaskListener listener) throws IOException {
    // TODO when we have support for trusted events, use the details from event if event was from trusted source
    listener.getLogger().printf("Looking up details of %s...%n", getRepoOwner());
    List<Action> result = new ArrayList<>();
    StandardCredentials credentials = Connector.lookupScanCredentials(owner, getApiUri(),
            getScanCredentialsId());
    GitHub hub = Connector.connect(getApiUri(), credentials);
    GHUser u = hub.getUser(getRepoOwner());
    String objectUrl = u.getHtmlUrl() == null ? null : u.getHtmlUrl().toExternalForm();
    result.add(new ObjectMetadataAction(Util.fixEmpty(u.getName()), null, objectUrl));
    result.add(new GitHubOrgMetadataAction(u));
    result.add(new GitHubLink("icon-github-logo", u.getHtmlUrl()));
    if (objectUrl == null) {
        listener.getLogger().println("Organization URL: unspecified");
    } else {
        listener.getLogger().printf("Organization URL: %s%n",
                HyperlinkNote.encodeTo(objectUrl, StringUtils.defaultIfBlank(u.getName(), objectUrl)));
    }
    return result;
}

From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.java

@Override
public SCM build(SCMHead head, SCMRevision revision) {
    if (revision == null) {
        // TODO will this work sanely for PRs? Branch.scm seems to be used only as a fallback for SCMBinder/SCMVar where they would perhaps better just report an error.
        return super.build(head, null);
    } else if (head instanceof PullRequestSCMHead) {
        if (revision instanceof PullRequestSCMRevision) {
            PullRequestSCMRevision prRev = (PullRequestSCMRevision) revision;
            // we rely on GitHub exposing the pull request revision on the target repository
            // TODO determine how we should name the checked out PR branch, as that affects the BRANCH_NAME env var
            SCMHead checkoutHead = head; // should probably have been head.getTarget() but historical
            GitSCM scm = (GitSCM) super.build(checkoutHead,
                    new SCMRevisionImpl(checkoutHead, prRev.getPullHash()));
            if (((PullRequestSCMHead) head).isMerge()) {
                scm.getExtensions().add(new MergeWith(
                        StringUtils.defaultIfBlank(((PullRequestSCMHead) head).getTarget().getName(), "master?" // OK if not found, just informational anyway
                        ), prRev.getBaseHash()));
            }//from   w  w  w  .  ja  va 2s  . c  om
            return scm;
        } else if (revision instanceof SCMRevisionImpl) {
            // this is a pull request from an untrusted collaborator
            return super.build(revision.getHead(), revision);
        } else {
            LOGGER.log(Level.WARNING, "Unexpected revision class {0} for {1}",
                    new Object[] { revision.getClass().getName(), head });
            return super.build(head, revision);
        }
    } else {
        return super.build(head, /* casting just as an assertion */(SCMRevisionImpl) revision);
    }
}