List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:org.jfrog.hudson.ivy.ArtifactoryIvyConfigurator.java
/** * Clears the extra apostrophes from the start and the end of the string *//* w w w. ja va 2 s . c o m*/ private String clearApostrophes(String artifactPattern) { return StringUtils.removeEnd(StringUtils.removeStart(artifactPattern, "\""), "\""); }
From source file:org.jfrog.hudson.plugins.artifactory.config.ArtifactoryServer.java
@DataBoundConstructor public ArtifactoryServer(String serverId, String url, Credentials deployerCredentials, Credentials resolverCredentials, int timeout, boolean bypassProxy) { this.url = StringUtils.removeEnd(url, "/"); this.deployerCredentials = deployerCredentials; this.resolverCredentials = resolverCredentials; this.timeout = timeout > 0 ? timeout : DEFAULT_CONNECTION_TIMEOUT; this.bypassProxy = bypassProxy; this.id = serverId == null || serverId.isEmpty() ? url.hashCode() + "@" + System.currentTimeMillis() : serverId;//from w w w .ja va 2 s. co m }
From source file:org.jfrog.hudson.plugins.artifactory.util.PublisherContext.java
private String getCleanString(String stringToClean) { return StringUtils.removeEnd(StringUtils.removeStart(stringToClean, "\""), "\""); }
From source file:org.jfrog.teamcity.agent.util.PathHelper.java
public static String removeDoubleDotsFromPattern(String pattern) { if (pattern == null) { throw new IllegalArgumentException("Cannot remove double dots from a null pattern."); }/*w ww . j a va 2 s. co m*/ if (!pattern.contains("..")) { return pattern; } String[] splitPattern = pattern.split("/"); StringBuilder patternBuilder = new StringBuilder(); for (int i = 0; i < splitPattern.length; i++) { if (!"..".equals(splitPattern[i])) { patternBuilder.append(splitPattern[i]); if (i != (splitPattern.length - 1)) { patternBuilder.append("/"); } } } return StringUtils.removeEnd(patternBuilder.toString(), "/"); }
From source file:org.jfrog.teamcity.agent.util.PathHelper.java
public static String calculateTargetPath(File file, String relativePath, String targetPattern) { if (file == null) { throw new IllegalArgumentException("Cannot calculate a target path given a null file."); }// w ww . j a v a 2 s .c o m if (relativePath == null) { throw new IllegalArgumentException("Cannot calculate a target path given a null relative path."); } if (StringUtils.isBlank(targetPattern)) { return relativePath; } StringBuilder artifactPathBuilder = 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 = StringUtils.remove(relativePath, file.getName()); relativeParentPath = StringUtils.removeEnd(relativeParentPath, "/"); artifactPathBuilder.append(relativeParentPath); addedRelativeParent = true; } else { artifactPathBuilder.append(relativePath); } } else if (targetToken.startsWith("*.")) { String newFileName = FilenameUtils.removeExtension(file.getName()) + targetToken.substring(1); artifactPathBuilder.append(newFileName); } else if ("*".equals(targetToken)) { artifactPathBuilder.append(file.getName()); } else { if (StringUtils.isNotBlank(targetToken)) { artifactPathBuilder.append(targetToken); } if (lastToken) { if (artifactPathBuilder.length() > 0) { artifactPathBuilder.append("/"); } if (addedRelativeParent) { artifactPathBuilder.append(file.getName()); } else { artifactPathBuilder.append(relativePath); } } } if (!lastToken) { artifactPathBuilder.append("/"); } } return artifactPathBuilder.toString(); }
From source file:org.jfrog.teamcity.server.trigger.ArtifactoryPolledBuildTrigger.java
private void triggerPolling(PolledTriggerContext context, ServerConfigBean serverConfig, String username, String password, String repoKey) { String buildName = context.getBuildType().getExtendedName(); boolean foundChange = false; ArtifactoryBuildInfoClient client = getBuildInfoClient(serverConfig, username, password); List<BuildWatchedItem> replacedValues = Lists.newArrayList(); try {/*from w w w. java 2s. c om*/ Iterator<BuildWatchedItem> iterator = watchedItems.get(buildName).iterator(); while (iterator.hasNext()) { BuildWatchedItem buildWatchedItem = iterator.next(); //Preserve the user entered item path as is to keep it persistent with the map key String itemPath = buildWatchedItem.getItemPath(); //Format the path in another variable for use in a request String formattedPath = StringUtils.removeStart(itemPath.trim(), "/"); formattedPath = StringUtils.removeEnd(formattedPath, "/"); long itemValue = buildWatchedItem.getItemLastModified(); String itemUrl = repoKey + "/" + formattedPath; try { String itemLastModifiedString = client.getItemLastModified(itemUrl); long itemLastModified = format.parse(itemLastModifiedString).getTime(); if (itemValue != itemLastModified) { if (itemLastModified != 0) { replacedValues.add(new BuildWatchedItem(itemPath, itemLastModified)); String message = String.format( "Artifactory trigger has found changes on the watched " + "item '%s' for build '%s'. Last modified time was %s and is now %s.", itemUrl, buildName, format.format(itemValue), itemLastModifiedString); Loggers.SERVER.info(message); foundChange = true; } } else { replacedValues.add(buildWatchedItem); } } catch (Exception e) { Loggers.SERVER.error("Error occurred while polling for changes for build '" + buildName + "' on path '" + serverConfig.getUrl() + "/" + itemUrl + "': " + e.getMessage()); } } } finally { client.shutdown(); } if (foundChange) { watchedItems.replaceValues(buildName, replacedValues); SBuildType buildType = context.getBuildType(); buildType.addToQueue(context.getTriggerDescriptor().getTriggerName()); } }
From source file:org.jongo.sql.dialect.OracleDialect.java
@Override public String toStatementString(Insert insert) { if (insert.getColumns().isEmpty()) throw new IllegalArgumentException("An insert query can't be empty"); final StringBuilder b = new StringBuilder("INSERT INTO "); b.append(insert.getTable().getDatabase()).append("."); b.append(insert.getTable().getName()); if (!insert.getColumns().isEmpty()) { b.append(" ("); b.append(StringUtils.join(insert.getColumns().keySet(), ",")); b.append(") VALUES ("); b.append(StringUtils.removeEnd(StringUtils.repeat("?,", insert.getColumns().size()), ",")); b.append(")"); }/* www . j a v a2s.c o m*/ l.debug(b.toString()); return b.toString(); }
From source file:org.jongo.sql.dialect.SQLDialect.java
@Override public String toStatementString(final Insert insert) { if (insert.getColumns().isEmpty()) throw new IllegalArgumentException("An insert query can't be empty"); final StringBuilder b = new StringBuilder("INSERT INTO "); b.append(insert.getTable().getName()); if (!insert.getColumns().isEmpty()) { b.append(" ("); b.append(StringUtils.join(insert.getColumns().keySet(), ",")); b.append(") VALUES ("); b.append(StringUtils.removeEnd(StringUtils.repeat("?,", insert.getColumns().size()), ",")); b.append(")"); }/* w w w .ja va 2 s .com*/ l.debug(b.toString()); return b.toString(); }
From source file:org.jumpmind.util.FormatUtils.java
public static String[] wordWrap(String str, int lineSize) { if (str != null && str.length() > lineSize) { Pattern regex = Pattern.compile("(\\S\\S{" + lineSize + ",}|.{1," + lineSize + "})(\\s+|$)"); List<String> list = new ArrayList<String>(); Matcher m = regex.matcher(str); while (m.find()) { String group = m.group(); // Preserve multiple newlines String[] lines = StringUtils.splitPreserveAllTokens(group, '\n'); for (String line : lines) { // Trim whitespace from end since a space on the end can // push line wrap and cause an unintentional blank line. line = StringUtils.removeEnd(line, " "); list.add(line);/*from ww w . j av a2s . c o m*/ } } return (String[]) list.toArray(new String[list.size()]); } else { return new String[] { str }; } }
From source file:org.kuali.kfs.gl.batch.service.impl.FileEnterpriseFeederServiceImpl.java
/** * Given the doneFile, this method finds the data file corresponding to the done file * //from w w w . j a va2s. c o m * @param doneFile * @return a File for the data file, or null if the file doesn't exist or is not readable */ protected File getDataFile(File doneFile) { String doneFileAbsPath = doneFile.getAbsolutePath(); if (!doneFileAbsPath.endsWith(DONE_FILE_SUFFIX)) { LOG.error("Done file name must end with " + DONE_FILE_SUFFIX); throw new IllegalArgumentException("Done file name must end with " + DONE_FILE_SUFFIX); } String dataFileAbsPath = StringUtils.removeEnd(doneFileAbsPath, DONE_FILE_SUFFIX) + DATA_FILE_SUFFIX; File dataFile = new File(dataFileAbsPath); if (!dataFile.exists() || !dataFile.canRead()) { LOG.error("Cannot find/read data file " + dataFileAbsPath); return null; } return dataFile; }