List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:org.jboss.windup.rules.apps.java.scan.ast.VariableResolvingASTVisitor.java
private List<String> methodParameterGuesser(List<?> arguements) { List<String> resolvedParams = new ArrayList<String>(arguements.size()); for (Object o : arguements) { if (o instanceof SimpleName) { String name = nameInstance.get(o.toString()); if (name != null) { resolvedParams.add(name); } else { resolvedParams.add("Undefined"); }/*from w ww .j ava2 s .c om*/ } else if (o instanceof StringLiteral) { resolvedParams.add("java.lang.String"); } else if (o instanceof FieldAccess) { String field = ((FieldAccess) o).getName().toString(); if (names.contains(field)) { resolvedParams.add(nameInstance.get(field)); } else { resolvedParams.add("Undefined"); } } else if (o instanceof CastExpression) { String type = ((CastExpression) o).getType().toString(); type = qualifyType(type); resolvedParams.add(type); } else if (o instanceof MethodInvocation) { String on = ((MethodInvocation) o).getName().toString(); if (StringUtils.equals(on, "toString")) { if (((MethodInvocation) o).arguments().size() == 0) { resolvedParams.add("java.lang.String"); } } else { resolvedParams.add("Undefined"); } } else if (o instanceof NumberLiteral) { if (StringUtils.endsWith(o.toString(), "L")) { resolvedParams.add("long"); } else if (StringUtils.endsWith(o.toString(), "f")) { resolvedParams.add("float"); } else if (StringUtils.endsWith(o.toString(), "d")) { resolvedParams.add("double"); } else { resolvedParams.add("int"); } } else if (o instanceof BooleanLiteral) { resolvedParams.add("boolean"); } else if (o instanceof ClassInstanceCreation) { String nodeType = ((ClassInstanceCreation) o).getType().toString(); nodeType = resolveClassname(nodeType); resolvedParams.add(nodeType); } else if (o instanceof org.eclipse.jdt.core.dom.CharacterLiteral) { resolvedParams.add("char"); } else if (o instanceof InfixExpression) { String expression = o.toString(); if (StringUtils.contains(expression, "\"")) { resolvedParams.add("java.lang.String"); } else { resolvedParams.add("Undefined"); } } else { LOG.finer("Unable to determine type: " + o.getClass() + ReflectionToStringBuilder.toString(o)); resolvedParams.add("Undefined"); } } return resolvedParams; }
From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java
private boolean archiveEndInEntryOfInterest(String entryName) { for (String extension : kae) { if (StringUtils.endsWith(entryName, extension)) { return true; }/*ww w. j ava2 s.c o m*/ } return false; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java
/** * Tries as best as possible to guess the repository HTML url to use with {@link GithubWeb}. * * @param owner the owner.// ww w .j a v a 2 s.c om * @param repo the repository. * @return the HTML url of the repository or {@code null} if we could not determine the answer. */ @CheckForNull public final String repositoryUrl(String owner, String repo) { if (repositoryUrl != null) { if (repoOwner.equals(owner) && repository.equals(repo)) { return repositoryUrl.toExternalForm(); } // hack! return repositoryUrl.toExternalForm().replace(repoOwner + "/" + repository, owner + "/" + repo); } if (StringUtils.isBlank(apiUri) || GitHubServerConfig.GITHUB_URL.equals(apiUri)) { return "https://github.com/" + owner + "/" + repo; } if (StringUtils.endsWith(StringUtils.removeEnd(apiUri, "/"), "/" + API_V3)) { return StringUtils.removeEnd(StringUtils.removeEnd(apiUri, "/"), API_V3) + owner + "/" + repo; } return null; }
From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java
private static Multimap<String, File> getUploadPathsMap(List<File> files, File checkoutDir, String targetPath, boolean flat, Pattern regexPattern) { Multimap<String, File> filePathsMap = HashMultimap.create(); for (File file : files) { String fileTargetPath = targetPath; String path;//from w w w . j av a2 s. com if (!StringUtils.endsWith(fileTargetPath, "/")) { path = StringUtils.substringBeforeLast(fileTargetPath, "/"); } else { path = targetPath; } if (!flat) { fileTargetPath = calculateFileTargetPath(checkoutDir, file, path); // handle win file system fileTargetPath = fileTargetPath.replace('\\', '/'); } fileTargetPath = PathsUtils.reformatRegexp(getRelativePath(checkoutDir, file), fileTargetPath, regexPattern); filePathsMap.put(fileTargetPath, file); } return filePathsMap; }
From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java
private static String ensureEnds(String s, char endsWith) { return StringUtils.endsWith(s, "/") ? s : (new StringBuilder()).append(s).append(endsWith).toString(); }
From source file:org.jspringbot.keyword.config.ConfigHelper.java
private void addProperties(String domain, File file) throws IOException { String filename = file.getName(); Properties properties = new Properties(); if (StringUtils.endsWith(filename, ".properties")) { properties.load(new FileReader(file)); } else if (StringUtils.endsWith(filename, ".xml")) { properties.loadFromXML(new FileInputStream(file)); }/* w w w. j a va2 s . c om*/ domainProperties.put(domain, properties); }
From source file:org.jspringbot.keyword.config.ConfigHelper.java
public void init() throws IOException { ResourceEditor editor = new ResourceEditor(); editor.setAsText("classpath:config/"); Resource configDirResource = (Resource) editor.getValue(); boolean hasConfigDirectory = true; boolean hasConfigProperties = true; if (configDirResource != null) { try {/*from www.j a va 2 s . co m*/ File configDir = configDirResource.getFile(); if (configDir.isDirectory()) { File[] propertiesFiles = configDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml"); } }); for (File propFile : propertiesFiles) { String filename = propFile.getName(); String name = StringUtils.substring(filename, 0, StringUtils.indexOf(filename, ".")); addProperties(name, propFile); } } } catch (IOException e) { hasConfigDirectory = false; } } editor.setAsText("classpath:config.properties"); Resource configPropertiesResource = (Resource) editor.getValue(); if (configPropertiesResource != null) { try { File configPropertiesFile = configPropertiesResource.getFile(); if (configPropertiesFile.isFile()) { Properties configs = new Properties(); configs.load(new FileReader(configPropertiesFile)); for (Map.Entry entry : configs.entrySet()) { String name = (String) entry.getKey(); editor.setAsText(String.valueOf(entry.getValue())); try { Resource resource = (Resource) editor.getValue(); addProperties(name, resource.getFile()); } catch (Exception e) { throw new IOException(String.format("Unable to load config '%s'.", name), e); } } } } catch (IOException e) { hasConfigProperties = false; } } if (!hasConfigDirectory && !hasConfigProperties) { LOGGER.warn("No configuration found."); } }
From source file:org.jspringbot.keyword.db.DbHelper.java
private void addExternalQueries(File file) throws IOException { String filename = file.getName(); Properties properties = new Properties(); if (StringUtils.endsWith(filename, ".properties")) { properties.load(new FileReader(file)); } else if (StringUtils.endsWith(filename, ".xml")) { properties.loadFromXML(new FileInputStream(file)); }/*from w w w . ja va2 s . co m*/ externalQueries.putAll(properties); }
From source file:org.jspringbot.keyword.db.DbHelper.java
public void init() { ResourceEditor editor = new ResourceEditor(); editor.setAsText("classpath:db-queries/"); Resource dbDirResource = (Resource) editor.getValue(); boolean hasDBDirectory = true; boolean hasDBProperties = true; if (dbDirResource != null) { try {//from w w w . jav a 2 s.co m File configDir = dbDirResource.getFile(); if (configDir.isDirectory()) { File[] propertiesFiles = configDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml"); } }); for (File propFile : propertiesFiles) { addExternalQueries(propFile); } } } catch (IOException ignore) { hasDBDirectory = false; } } editor.setAsText("classpath:db-queries.properties"); Resource dbPropertiesResource = (Resource) editor.getValue(); if (dbPropertiesResource != null) { try { if (dbPropertiesResource.getFile().isFile()) { addExternalQueries(dbPropertiesResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } editor.setAsText("classpath:db-queries.xml"); Resource dbXMLResource = (Resource) editor.getValue(); if (dbXMLResource != null && !hasDBProperties) { try { if (dbXMLResource.getFile().isFile()) { addExternalQueries(dbXMLResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } if (!hasDBDirectory && !hasDBProperties) { LOGGER.warn("No query sources found."); } begin(); }
From source file:org.jumpmind.metl.core.runtime.resource.SftpDirectory.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from www. j a va 2s. c o m*/ public List<FileInfo> listFiles(boolean closeSession, String... relativePaths) { ChannelSftp sftp = null; String separator = null; List<FileInfo> fileInfoList = new ArrayList<>(); try { // Get a reusable channel if the session is not auto closed. sftp = (closeSession) ? openConnectedChannel() : openConnectedChannel(CHANNEL_1); sftp.cd(basePath); for (String relativePath : relativePaths) { if (!relativePath.equals(".") && !relativePath.equals("..")) { if (relativePath.isEmpty() || StringUtils.endsWith(relativePath, "/")) { separator = ""; } else { separator = "/"; } Vector list = new Vector(); try { list.addAll(sftp.ls(relativePath.isEmpty() ? "*" : relativePath)); } catch (SftpException e) { log.warn("List File Warning ==>" + e.getMessage()); } for (Object object : list) { LsEntry entry = (LsEntry) object; if (!entry.getFilename().equals(".") && !entry.getFilename().equals("..")) { fileInfoList.add(new FileInfo(relativePath + separator + entry.getFilename(), entry.getAttrs().isDir(), entry.getAttrs().getMTime(), entry.getAttrs().getSize())); } } } } return fileInfoList; } catch (Exception e) { throw new RuntimeException( String.format("Failure in listFiles for SFTP. Error ==> %s", e.getMessage()), e); } finally { if (closeSession) { close(); } } }