private String getCustomizedPackageName(String serviceName, String defaultPattern) { return String.format(defaultPattern, StringUtils.lowerCase(serviceName)); }
private String standardizePath(String path) { if (StringUtils.isEmpty(path)) { return ""; } StringBuilder standardizedPath = new StringBuilder(); // Path must always start with '/' if (!path.startsWith("/")) { standardizedPath.append('/'); } standardizedPath.append(path); return standardizedPath.toString(); }
private String joinPackageNames(String lhs, String rhs) { return StringUtils.isBlank(rhs) ? lhs : lhs + '.' + rhs; }
/** * <p>Removes control characters (char <= 32) from both * ends of this String returning {@code null} if the String is * empty ("") after the trim or if it is {@code null}. * * <p>The String is trimmed using {@link String#trim()}. * Trim removes start and end characters <= 32.</p> * * <pre> * StringUtils.trimToNull(null) = null * StringUtils.trimToNull("") = null * StringUtils.trimToNull(" ") = null * StringUtils.trimToNull("abc") = "abc" * StringUtils.trimToNull(" abc ") = "abc" * </pre> * * @param str the String to be trimmed, may be null * @return the trimmed String, * {@code null} if only chars <= 32, empty or null String input * @since 2.0 */ public static String trimToNull(final String str) { String ts = trim(str); return isEmpty(ts) ? null : ts; }
private String deriveLocationNameForEc2(Member member) { String locationName = member.getLocationName(); if (StringUtils.isNotBlank(locationName)) { return StringUtils.upperCase(locationName.substring(0, 1)) + locationName.substring(1); } return null; }
private StringBuilder getUserAgent(SdkClientConfiguration config, List<ApiName> requestApiNames) { String userDefinedPrefix = config.option(SdkAdvancedClientOption.USER_AGENT_PREFIX); String awsExecutionEnvironment = SdkSystemSetting.AWS_EXECUTION_ENV.getStringValue().orElse(null); StringBuilder userAgent = new StringBuilder(StringUtils.trimToEmpty(userDefinedPrefix)); String systemUserAgent = UserAgentUtils.getUserAgent(); if (!systemUserAgent.equals(userDefinedPrefix)) { userAgent.append(COMMA).append(systemUserAgent); } if (!StringUtils.isEmpty(awsExecutionEnvironment)) { userAgent.append(SPACE).append(AWS_EXECUTION_ENV_PREFIX).append(awsExecutionEnvironment.trim()); } if (!requestApiNames.isEmpty()) { String requestUserAgent = requestApiNames.stream() .map(n -> n.name() + "/" + n.version()) .collect(Collectors.joining(" ")); userAgent.append(SPACE).append(requestUserAgent); } return userAgent; }
/** * Given a property line, load the property key and value. If the property line is invalid and should be ignored, this will * return empty. */ private static Optional<Pair<String, String>> parsePropertyDefinition(ParserState state, String line) { int firstEqualsLocation = line.indexOf('='); Validate.isTrue(firstEqualsLocation != -1, "Expected an '=' sign defining a property on line " + state.currentLineNumber); String propertyKey = StringUtils.trim(line.substring(0, firstEqualsLocation)); String propertyValue = StringUtils.trim(line.substring(firstEqualsLocation + 1)); Validate.isTrue(!propertyKey.isEmpty(), "Property did not have a name on line " + state.currentLineNumber); // If the profile name includes invalid characters, it should be ignored. if (!isValidIdentifier(propertyKey)) { log.warn(() -> "Ignoring property '" + propertyKey + "' on line " + state.currentLineNumber + " because " + "its name was not alphanumeric with dashes or underscores."); return Optional.empty(); } return Optional.of(Pair.of(propertyKey, propertyValue)); }
private boolean hasReturn() { return StringUtils.isNotBlank(returns); }
private void validateFileContentMatches(File outputFile, String newFileContents) throws IOException { byte[] currentFileBytes = Files.readAllBytes(outputFile.toPath()); String currentFileContents = new String(currentFileBytes, StandardCharsets.UTF_8); String currentContentForComparison = codeComparisonTransformer.apply(currentFileContents); String newContentForComparison = codeComparisonTransformer.apply(newFileContents); if (!StringUtils.equals(currentContentForComparison, newContentForComparison)) { throw new IllegalStateException("Attempted to clobber existing file (" + outputFile + ") with a new file that has " + "different content. This may indicate forgetting to clean up old generated files " + "before running the generator?\n" + "Existing file: \n" + currentContentForComparison + "\n\n" + "New file: \n" + newContentForComparison); } } }
/** * <p>Removes control characters (char <= 32) from both * ends of this String returning {@code null} if the String is * empty ("") after the trim or if it is {@code null}. * * <p>The String is trimmed using {@link String#trim()}. * Trim removes start and end characters <= 32.</p> * * <pre> * StringUtils.trimToNull(null) = null * StringUtils.trimToNull("") = null * StringUtils.trimToNull(" ") = null * StringUtils.trimToNull("abc") = "abc" * StringUtils.trimToNull(" abc ") = "abc" * </pre> * * @param str the String to be trimmed, may be null * @return the trimmed String, * {@code null} if only chars <= 32, empty or null String input * @since 2.0 */ public static String trimToNull(final String str) { String ts = trim(str); return isEmpty(ts) ? null : ts; }
/** * Given a property line, load the property key and value. If the property line is invalid and should be ignored, this will * return empty. */ private static Optional<Pair<String, String>> parsePropertyDefinition(ParserState state, String line) { int firstEqualsLocation = line.indexOf('='); Validate.isTrue(firstEqualsLocation != -1, "Expected an '=' sign defining a property on line " + state.currentLineNumber); String propertyKey = StringUtils.trim(line.substring(0, firstEqualsLocation)); String propertyValue = StringUtils.trim(line.substring(firstEqualsLocation + 1)); Validate.isTrue(!propertyKey.isEmpty(), "Property did not have a name on line " + state.currentLineNumber); // If the profile name includes invalid characters, it should be ignored. if (!isValidIdentifier(propertyKey)) { log.warn(() -> "Ignoring property '" + propertyKey + "' on line " + state.currentLineNumber + " because " + "its name was not alphanumeric with dashes or underscores."); return Optional.empty(); } return Optional.of(Pair.of(propertyKey, propertyValue)); }
private boolean hasReturn() { return StringUtils.isNotBlank(returns); }
private String deriveLocationNameForEc2(Member member) { String locationName = member.getLocationName(); if (StringUtils.isNotBlank(locationName)) { return StringUtils.upperCase(locationName.substring(0, 1)) + locationName.substring(1); } return null; }
private void validateFileContentMatches(File outputFile, String newFileContents) throws IOException { byte[] currentFileBytes = Files.readAllBytes(outputFile.toPath()); String currentFileContents = new String(currentFileBytes, StandardCharsets.UTF_8); String currentContentForComparison = codeComparisonTransformer.apply(currentFileContents); String newContentForComparison = codeComparisonTransformer.apply(newFileContents); if (!StringUtils.equals(currentContentForComparison, newContentForComparison)) { throw new IllegalStateException("Attempted to clobber existing file (" + outputFile + ") with a new file that has " + "different content. This may indicate forgetting to clean up old generated files " + "before running the generator?\n" + "Existing file: \n" + currentContentForComparison + "\n\n" + "New file: \n" + newContentForComparison); } } }
private boolean shouldExcludeHeaderFromSigning(String header) { return LIST_OF_HEADERS_TO_IGNORE_IN_LOWER_CASE.contains(lowerCase(header)); }
@Override public String getJavaClassName(String shapeName) { return Arrays.stream(shapeName.split("[._-]|\\W")) .filter(s -> !StringUtils.isEmpty(s)) .map(Utils::capitalize) .collect(joining()); }
@Override public AwsCredentials resolveCredentials() { String accessKey = trim(loadSetting(SdkSystemSetting.AWS_ACCESS_KEY_ID).orElse(null)); String secretKey = trim(loadSetting(SdkSystemSetting.AWS_SECRET_ACCESS_KEY).orElse(null)); String sessionToken = trim(loadSetting(SdkSystemSetting.AWS_SESSION_TOKEN).orElse(null)); if (StringUtils.isEmpty(accessKey)) { throw SdkClientException.builder() .message(String.format("Unable to load credentials from system settings. Access key must be" + " specified either via environment variable (%s) or system property (%s).", SdkSystemSetting.AWS_ACCESS_KEY_ID.environmentVariable(), SdkSystemSetting.AWS_ACCESS_KEY_ID.property())) .build(); } if (StringUtils.isEmpty(secretKey)) { throw SdkClientException.builder() .message(String.format("Unable to load credentials from system settings. Secret key must be" + " specified either via environment variable (%s) or system property (%s).", SdkSystemSetting.AWS_SECRET_ACCESS_KEY.environmentVariable(), SdkSystemSetting.AWS_SECRET_ACCESS_KEY.property())) .build(); } return sessionToken == null ? AwsBasicCredentials.create(accessKey, secretKey) : AwsSessionCredentials.create(accessKey, secretKey, sessionToken); }
/** * Read a property continuation line and update the parser state with the results. This adds the value in the continuation * to the current property, prefixed with a newline. * * Non-Blank Parent Property: Whitespace Value Whitespace? * Blank Parent Property (Sub-Property): Whitespace Identifier Whitespace? = Whitespace? Value Whitespace? */ private static void readPropertyContinuationLine(ParserState state, String line) { // If we're in an invalid profile or property, ignore its continuations if (state.ignoringCurrentProfile || state.ignoringCurrentProperty) { return; } Validate.isTrue(state.currentProfileBeingRead != null && state.currentPropertyBeingRead != null, "Expected a profile or property definition on line " + state.currentLineNumber); // Comments are not removed on property continuation lines. They're considered part of the value. line = StringUtils.trim(line); Map<String, String> profileProperties = state.profiles.get(state.currentProfileBeingRead); String currentPropertyValue = profileProperties.get(state.currentPropertyBeingRead); String newPropertyValue = currentPropertyValue + "\n" + line; // If this is a sub-property, make sure it can be parsed correctly by the CLI. if (state.validatingContinuationsAsSubProperties) { parsePropertyDefinition(state, line); } profileProperties.put(state.currentPropertyBeingRead, newPropertyValue); }
private String joinPackageNames(String lhs, String rhs) { return StringUtils.isBlank(rhs) ? lhs : lhs + '.' + rhs; }
public static void addJavadoc(Consumer<String> builder, String javadoc) { if (isNotBlank(javadoc)) { builder.accept(javadoc.replace("$", "$$") + (javadoc.endsWith("\n") ? "" : "\n")); } }