Refine search
/** * <p> * Checks if a CharSequence is not empty ("") and not null. * </p> * * <pre> * Strings.isNotEmpty(null) = false * Strings.isNotEmpty("") = false * Strings.isNotEmpty(" ") = true * Strings.isNotEmpty("bob") = true * Strings.isNotEmpty(" bob ") = true * </pre> * * <p> * Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence) * </p> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is not empty and not null */ public static boolean isNotEmpty(final CharSequence cs) { return !isEmpty(cs); }
/** * Checks if a String is not blank. The opposite of {@link #isBlank(String)}. * * @param s the String to check, may be {@code null} * @return {@code true} if the String is non-{@code null} and has content after being trimmed. */ public static boolean isNotBlank(final String s) { return !isBlank(s); }
if (Strings.isNotEmpty(logName)) { sb.append(logName); sb.append(SPACE);
/** * Factory method for creating a connection source within the plugin manager. * * @param jndiName The full JNDI path where the data source is bound. Should start with java:/comp/env or * environment-equivalent. * @return the created connection source. */ @PluginFactory public static DataSourceConnectionSource createConnectionSource(@PluginAttribute("jndiName") final String jndiName) { if (Strings.isEmpty(jndiName)) { LOGGER.error("No JNDI name provided."); return null; } try { final InitialContext context = new InitialContext(); final DataSource dataSource = (DataSource) context.lookup(jndiName); if (dataSource == null) { LOGGER.error("No data source found with JNDI name [" + jndiName + "]."); return null; } return new DataSourceConnectionSource(jndiName, dataSource); } catch (final NamingException e) { LOGGER.error(e.getMessage(), e); return null; } } }
@Override public ColumnConfig build() { if (Strings.isEmpty(name)) { LOGGER.error("The column config is not valid because it does not contain a column name."); return null; final boolean isPattern = Strings.isNotEmpty(pattern); final boolean isLiteralValue = Strings.isNotEmpty(literal); LOGGER.error("The pattern, literal, and isEventTimestamp attributes are mutually exclusive."); return null; LOGGER.error("To configure a column you must specify a pattern or literal or set isEventDate to true."); return null;
@Override public void contextDestroyed(final ServletContextEvent event) { if (this.servletContext == null || this.initializer == null) { LOGGER.warn("Context destroyed before it was initialized."); return; } LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly."); this.initializer.clearLoggerContext(); // the application is finished // shutting down now if (initializer instanceof LifeCycle2) { final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT); final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT : Long.parseLong(stopTimeoutStr); final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT); final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT)); ((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit); } else { this.initializer.stop(); } } }
@Override public void exec(Plugin plugin) { log.trace("Push tags to local"); if (!Strings.isBlank(plugin.getPluginDetail().getImage()) && !Strings .isBlank(plugin.getPluginDetail().getBuild())) { return; } try { // put from cache to local git workspace Path cachePath = gitCachePath(plugin); String latestGitTag = plugin.getTag(); JGitUtil.push(cachePath, LOCAL_REMOTE, latestGitTag); // set currentTag latestTag plugin.setCurrentTag(latestGitTag); updatePluginStatus(plugin, INSTALLED); } catch (GitException e) { log.error("Git Push", e); throw new PluginException("Git Push", e); } }
@Override public PosixViewAttributeAction build() { if (Strings.isEmpty(basePath)) { LOGGER.error("Posix file attribute view action not valid because base path is empty."); return null; } if (filePermissions == null && Strings.isEmpty(filePermissionsString) && Strings.isEmpty(fileOwner) && Strings.isEmpty(fileGroup)) { LOGGER.error("Posix file attribute view not valid because nor permissions, user or group defined."); return null; } if (!FileUtils.isFilePosixAttributeViewSupported()) { LOGGER.warn("Posix file attribute view defined but it is not supported by this files system."); return null; } return new PosixViewAttributeAction(basePath, followLinks, maxDepth, pathConditions, subst != null ? subst : configuration.getStrSubstitutor(), filePermissions != null ? filePermissions : filePermissionsString != null ? PosixFilePermissions.fromString(filePermissionsString) : null, fileOwner, fileGroup); }
@PluginFactory public static LlapWrappedAppender createAppender( @PluginAttribute("name") final String name, // This isn't really used for anything. @PluginAttribute("renameFileOnClose") final String renameFileOnCloseProvided, @PluginAttribute("renamedFileSuffix") final String renamedFileSuffixProvided, @PluginNode final Node node, @PluginConfiguration final Configuration config ) { if (config == null) { LOGGER.error("PluginConfiguration not expected to be null"); return null; } if (node == null) { LOGGER.error("Node must be specified as an appender specification"); return null; } boolean renameFileOnClose = DEFAULT_RENAME_FILES_ON_CLOSE; if (Strings.isNotBlank(renameFileOnCloseProvided)) { renameFileOnClose = Boolean.parseBoolean(renameFileOnCloseProvided); } String renamedFileSuffix = DEFAULT_RENAMED_FILE_SUFFIX; if (Strings.isNotBlank(renamedFileSuffixProvided)) { renamedFileSuffix = renamedFileSuffixProvided; } return new LlapWrappedAppender(name, node, config, renameFileOnClose, renamedFileSuffix); }
@Override public Object visit(final Configuration configuration, final Node node, final LogEvent event, final StringBuilder log) { final String name = this.annotation.value(); final String elementValue = node.getValue(); final String attributeValue = node.getAttributes().get("value"); String rawValue = null; // if neither is specified, return null (LOG4J2-1313) if (Strings.isNotEmpty(elementValue)) { if (Strings.isNotEmpty(attributeValue)) { LOGGER.error("Configuration contains {} with both attribute value ({}) AND element" + " value ({}). Please specify only one value. Using the element value.", node.getName(), attributeValue, elementValue); } rawValue = elementValue; } else { rawValue = removeAttributeValue(node.getAttributes(), "value"); } final String value = this.substitutor.replace(event, rawValue); StringBuilders.appendKeyDqValue(log, name, value); return value; } }
/** Logs the Peer connections for each node. */ public void logPeerConnections() { final List<String> connStr = new ArrayList<>(); for (final TestNode node : nodes) { for (final PeerConnection peer : node.network.getPeers()) { final String localString = node.shortId() + "@" + peer.getLocalAddress(); final String peerString = shortId(peer.getPeer().getNodeId()) + "@" + peer.getRemoteAddress(); connStr.add("Connection: " + localString + " to " + peerString); } } LOG.info("TestNodeList Connections:\n" + join(connStr, '\n')); }
if ("endpoint".equalsIgnoreCase(property.getName())) { final String value = property.getValue(); if (Strings.isNotEmpty(value)) { endpoints.add(value); LOGGER.debug("Creating JeroMqAppender with name={}, filter={}, layout={}, ignoreExceptions={}, endpoints={}", name, filter, layout, ignoreExceptions, endpoints); return new JeroMqAppender(name, filter, layout, ignoreExceptions, endpoints, affinity, backlog,
private Configuration getConfiguration(final LoggerContext loggerContext, final boolean isTest, final String name) { final boolean named = Strings.isNotEmpty(name); final ClassLoader loader = LoaderUtil.getThreadContextClassLoader(); for (final ConfigurationFactory factory : getFactories()) { String configName; final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX; final String [] types = factory.getSupportedTypes(); if (types == null) { continue; } for (final String suffix : types) { if (suffix.equals(ALL_TYPES)) { continue; } configName = named ? prefix + name + suffix : prefix + suffix; final ConfigurationSource source = ConfigurationSource.fromResource(configName, loader); if (source != null) { if (!factory.isActive()) { LOGGER.warn("Found configuration file {} for inactive ConfigurationFactory {}", configName, factory.getClass().getName()); } return factory.getConfiguration(loggerContext, source); } } } return null; }
private AppenderRefComponentBuilder createAppenderRef(final String key, final Properties properties) { final String ref = (String) properties.remove("ref"); if (Strings.isEmpty(ref)) { throw new ConfigurationException("No ref attribute provided for AppenderRef " + key); } final AppenderRefComponentBuilder appenderRefBuilder = builder.newAppenderRef(ref); final String level = Strings.trimToNull((String) properties.remove("level")); if (!Strings.isEmpty(level)) { appenderRefBuilder.addAttribute("level", level); } return addFiltersToComponent(appenderRefBuilder, properties); }
/** * <p>Joins the elements of the provided {@code Iterable} into * a single String containing the provided elements.</p> * * <p>No delimiter is added before or after the list. Null objects or empty * strings within the iteration are represented by empty strings.</p> * * @param iterable the {@code Iterable} providing the values to join together, may be null * @param separator the separator character to use * @return the joined String, {@code null} if null iterator input */ public static String join(final Iterable<?> iterable, final char separator) { if (iterable == null) { return null; } return join(iterable.iterator(), separator); }
if (isLocalFs) { String buildDir = System.getProperty(BUILD_DIR_PROPERTY); Preconditions.checkState(Strings.isNotBlank(buildDir)); Path path = new Path(fsUriString, buildDir);
/** * A Constructor that helps conformance to RFC 5424. * * @param name The name portion of the id. * @param enterpriseNumber The enterprise number. * @param required The list of keys that are required for this id. * @param optional The list of keys that are optional for this id. * @param maxLength The maximum length of the StructuredData Id key. * @since 2.9 */ public StructuredDataId(final String name, final int enterpriseNumber, final String[] required, final String[] optional, final int maxLength) { if (name == null) { throw new IllegalArgumentException("No structured id name was supplied"); } if (name.contains(AT_SIGN)) { throw new IllegalArgumentException("Structured id name cannot contain an " + Strings.quote(AT_SIGN)); } if (enterpriseNumber <= 0) { throw new IllegalArgumentException("No enterprise number was supplied"); } this.name = name; this.enterpriseNumber = enterpriseNumber; final String id = name + AT_SIGN + enterpriseNumber; if (maxLength > 0 && id.length() > maxLength) { throw new IllegalArgumentException("Length of id exceeds maximum of " + maxLength + " characters: " + id); } this.required = required; this.optional = optional; }