List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.jfrog.bamboo.context.AbstractBuildContext.java
private static String getBuilderValue(Map<String, String> confMap) { for (Map.Entry<String, String> entry : confMap.entrySet()) { if (StringUtils.startsWith(entry.getKey(), "builder.")) { return entry.getKey(); }/*w w w . ja v a 2 s.co m*/ } return null; }
From source file:org.jfrog.build.extractor.BuildInfoExtractorUtils.java
public static Properties getEnvProperties(Properties startProps, Log log) { IncludeExcludePatterns patterns = new IncludeExcludePatterns( startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_INCLUDE_PATTERNS), startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_EXCLUDE_PATTERNS)); Properties props = new Properties(); // Add all the startProps that starts with BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX for (Map.Entry<Object, Object> startEntry : startProps.entrySet()) { if (StringUtils.startsWith((String) startEntry.getKey(), BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX)) { props.put(startEntry.getKey(), startEntry.getValue()); }/* w w w . jav a 2 s. c om*/ } // Add all system environment that match the patterns Map<String, String> envMap = System.getenv(); for (Map.Entry<String, String> entry : envMap.entrySet()) { String varKey = entry.getKey(); if (PatternMatcher.pathConflicts(varKey, patterns)) { continue; } props.put(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + varKey, entry.getValue()); } Map<String, String> sysProps = new HashMap(System.getProperties()); Map<String, String> filteredSysProps = Maps.difference(sysProps, System.getenv()).entriesOnlyOnLeft(); for (Map.Entry<String, String> entry : filteredSysProps.entrySet()) { String varKey = entry.getKey(); if (PatternMatcher.pathConflicts(varKey, patterns)) { continue; } props.put(varKey, entry.getValue()); } // TODO: [by FSI] Test if this is needed! Since start props are used now String propertiesFilePath = getAdditionalPropertiesFile(startProps, log); if (StringUtils.isNotBlank(propertiesFilePath)) { File propertiesFile = new File(propertiesFilePath); InputStream inputStream = null; try { if (propertiesFile.exists()) { inputStream = new FileInputStream(propertiesFile); Properties propertiesFromFile = new Properties(); propertiesFromFile.load(inputStream); props.putAll(filterDynamicProperties(propertiesFromFile, ENV_PREDICATE)); } } catch (IOException e) { throw new RuntimeException( "Unable to load build info properties from file: " + propertiesFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStream); } } return props; }
From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java
/** * Calculates the target deployment path of an artifact by it's name * * @param targetPattern an Ant pattern of the target path * @param artifactFile the artifact file to calculate target deployment path for * @return the calculated target path//ww w.ja v a 2s. c o m */ public static String calculateTargetPath(String targetPattern, File artifactFile) { String relativePath = calculateTargetRelativePath(artifactFile); if (relativePath == null) { throw new IllegalArgumentException("Cannot calculate a target path given a null relative path."); } if (StringUtils.isBlank(targetPattern)) { return relativePath; } relativePath = FilenameUtils.separatorsToUnix(relativePath); targetPattern = FilenameUtils.separatorsToUnix(targetPattern); // take care of absolute path if (StringUtils.startsWith(targetPattern, "/")) { return targetPattern + "/" + artifactFile.getName(); } // take care of relative paths with patterns. StringBuilder itemPathBuilder = new StringBuilder(); String[] targetTokens = targetPattern.split("/"); boolean addedRelativeParent = false; for (int i = 0; i < targetTokens.length; i++) { boolean lastToken = (i == (targetTokens.length - 1)); String targetToken = targetTokens[i]; if ("**".equals(targetToken)) { if (!lastToken) { String relativeParentPath = FilenameUtils.getPathNoEndSeparator(relativePath); itemPathBuilder.append(relativeParentPath); addedRelativeParent = true; } else { itemPathBuilder.append(relativePath); } } else if (targetToken.startsWith("*.")) { String newFileName = FilenameUtils.removeExtension(FilenameUtils.getName(relativePath)) + targetToken.substring(1); itemPathBuilder.append(newFileName); } else if ("*".equals(targetToken)) { itemPathBuilder.append(FilenameUtils.getName(relativePath)); } else { if (StringUtils.isNotBlank(targetToken)) { itemPathBuilder.append(targetToken); } if (lastToken) { if (itemPathBuilder.length() > 0) { itemPathBuilder.append("/"); } if (addedRelativeParent) { itemPathBuilder.append(FilenameUtils.getName(relativePath)); } else { itemPathBuilder.append(relativePath); } } } if (!lastToken) { itemPathBuilder.append("/"); } } return itemPathBuilder.toString(); }
From source file:org.jspringbot.keyword.json.JSONHelper.java
public void setJsonString(String jsonString) throws IOException { if (StringUtils.startsWith(jsonString, "file:") || StringUtils.startsWith(jsonString, "classpath:")) { ResourceEditor editor = new ResourceEditor(); editor.setAsText(jsonString);/*from w w w . ja va 2s.c o m*/ Resource resource = (Resource) editor.getValue(); jsonString = new String(IOUtils.toCharArray(resource.getInputStream(), CharEncoding.UTF_8)); } if (!StringUtils.startsWith(jsonString, "[") || !StringUtils.startsWith(jsonString, "{")) { // LOG.warn("jsonString starts with an invalid character. trying to recover..."); for (int i = 0; i < jsonString.length(); i++) { if (jsonString.charAt(i) == '{' || jsonString.charAt(i) == '[') { jsonString = jsonString.substring(i); break; } } } try { LOG.createAppender().appendBold("JSON String:").appendJSON(prettyPrint(jsonString)).log(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } this.jsonString = jsonString; }
From source file:org.jspringbot.keyword.json.JSONHelper.java
public List<Object> getJsonValues(String jsonExpression) { validate();/*w w w .j a va2s. c o m*/ Object jsonValue; if (StringUtils.startsWith(jsonExpression, "$")) { jsonValue = JsonPath.read(jsonString, jsonExpression); } else { jsonValue = JsonPath.read(jsonString, "$." + jsonExpression); } List items; if (jsonValue instanceof List) { items = (List) jsonValue; } else { items = Arrays.asList(jsonValue); } LOG.createAppender().appendBold("Get JSON Values:").appendProperty("Json Expression", jsonExpression) .appendProperty("Size", items.size()).log(); return items; }
From source file:org.jspringbot.keyword.selenium.ElementFinder.java
private Locator parseLocator(String locatorStr) { Locator locator = new Locator(); locator.prefix = null;//from w w w. j a va2 s . c o m locator.criteria = locatorStr; if (!StringUtils.startsWith(locatorStr, "//")) { int equalIndexOf = locatorStr.indexOf('='); if (equalIndexOf != -1) { locator.prefix = locatorStr.substring(0, equalIndexOf); locator.criteria = locatorStr.substring(equalIndexOf + 1); } } return locator; }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
public Object executeJavascript(String code) throws IOException { HighlightRobotLogger.HtmlAppender appender = LOG.createAppender().appendBold("Execute Javascript:"); if (StringUtils.startsWith(code, "file:") || StringUtils.startsWith(code, "classpath:")) { appender.appendProperty("Resource", code); ResourceEditor editor = new ResourceEditor(); editor.setAsText(code);//from w w w. ja v a2 s . c o m Resource resource = (Resource) editor.getValue(); code = new String(IOUtils.toCharArray(resource.getInputStream())); } appender.appendJavascript(code); appender.log(); return executor.executeScript(code); }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
public int getMatchingCSSCount(String cssLocator) { if (StringUtils.startsWith(cssLocator, "css=")) { cssLocator = cssLocator.substring(4); }//from ww w . j a v a2s . c o m int count = driver.findElements(By.cssSelector(cssLocator)).size(); LOG.createAppender().appendBold("Get Matching CSS Count:").appendCss(cssLocator) .appendProperty("Count", count).log(); return count; }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
public int getMatchingXPathCount(String xpath) { if (StringUtils.startsWith(xpath, "xpath=")) { xpath = xpath.substring(6);// w ww .j a va 2s . co m } int count = driver.findElements(By.xpath(xpath)).size(); LOG.createAppender().appendBold("Get Matching XPath Count:").appendCss(xpath).appendProperty("Count", count) .log(); return count; }
From source file:org.jspringbot.keyword.test.data.CreateTestData.java
@Override @SuppressWarnings("unchecked") public Object execute(Object[] params) { try {//from ww w. jav a2 s . com List<String> list = new ArrayList<String>(); for (int i = 1; i < params.length; i++) { list.add(String.valueOf(params[i])); } String file = String.valueOf(params[0]); if (StringUtils.startsWith(file, "file:")) { file = StringUtils.substringAfter(file, "file:"); } helper.createTestData(new File(file), list); } catch (IOException e) { throw new IllegalArgumentException(e.getMessage(), e); } return null; }