Java Code Examples for org.eclipse.jgit.util.StringUtils#isEmptyOrNull()
The following examples show how to use
org.eclipse.jgit.util.StringUtils#isEmptyOrNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Compare the two given git remote URIs. This method is a reimplementation of {@link URIish#equals(Object)} with * one difference. The scheme of the URIs is only considered if both URIs have a non-null and non-empty scheme part. * * @param lhs * the left hand side * @param rhs * the right hand side * @return <code>true</code> if the two URIs are to be considered equal and <code>false</code> otherwise */ private static boolean equals(URIish lhs, URIish rhs) { // We only consider the scheme if both URIs have one if (!StringUtils.isEmptyOrNull(lhs.getScheme()) && !StringUtils.isEmptyOrNull(rhs.getScheme())) { if (!Objects.equals(lhs.getScheme(), rhs.getScheme())) return false; } if (!equals(lhs.getUser(), rhs.getUser())) return false; if (!equals(lhs.getPass(), rhs.getPass())) return false; if (!equals(lhs.getHost(), rhs.getHost())) return false; if (lhs.getPort() != rhs.getPort()) return false; if (!pathEquals(lhs.getPath(), rhs.getPath())) return false; return true; }
Example 2
Source File: GitUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static boolean pathEquals(String lhs, String rhs) { if (StringUtils.isEmptyOrNull(lhs) && StringUtils.isEmptyOrNull(rhs)) return true; // Skip leading slashes in both paths. int lhsIndex = 0; while (lhsIndex < lhs.length() && lhs.charAt(lhsIndex) == '/') ++lhsIndex; int rhsIndex = 0; while (rhsIndex < rhs.length() && rhs.charAt(rhsIndex) == '/') ++rhsIndex; String lhsRel = lhs.substring(lhsIndex); String rhsRel = rhs.substring(rhsIndex); return lhsRel.equals(rhsRel); }
Example 3
Source File: PushHookTriggerHandlerImpl.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
private String retrievePushedBy(final PushHook hook) { final String userName = hook.getUserName(); if (!StringUtils.isEmptyOrNull(userName)) { return userName; } final String userUsername = hook.getUserUsername(); if (!StringUtils.isEmptyOrNull(userUsername)) { return userUsername; } final List<Commit> commits = hook.getCommits(); if (commits != null && !commits.isEmpty()) { return commits.get(commits.size() - 1).getAuthor().getName(); } return null; }
Example 4
Source File: LfsAuthServlet.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
private Link createToken( @NotNull HttpServletRequest req, @Nullable URI uri, @Nullable String secretToken, @Nullable String userId, @Nullable String mode ) throws ServerError { // Check secretToken if (StringUtils.isEmptyOrNull(secretToken)) throw new ServerError(HttpServletResponse.SC_BAD_REQUEST, "Parameter \"secretToken\" not specified"); if (!this.secretToken.equals(secretToken)) throw new ServerError(HttpServletResponse.SC_FORBIDDEN, "Invalid secretToken"); final LfsAuthHelper.AuthMode authMode = LfsAuthHelper.AuthMode.find(mode); if (authMode == null) throw new ServerError(HttpServletResponse.SC_BAD_REQUEST, String.format("Unsupported mode: %s", mode)); return LfsAuthHelper.createToken(context.getShared(), uri != null ? uri : getWebServer().getUrl(req).resolve(baseLfsUrl), userId, authMode, tokenExpireSec, tokenExpireTime); }
Example 5
Source File: Main.java From diff-check with GNU Lesser General Public License v2.1 | 5 votes |
private static List<File> getGitDiffFilesToProcess(List<Pattern> patternsToExclude, CommandLine commandLine) { String gitDirPath = commandLine.getOptionValue(OPTION_GIT_DIR_NAME); File repoDir = new File(gitDirPath); if (!repoDir.isDirectory()) { System.out.println("git directory " + gitDirPath + " is not a directory!"); System.exit(1); } String oldRev = commandLine.getOptionValue(OPTION_GIT_BASE_REV_NAME); boolean includeStagedCodes = commandLine.hasOption(OPTION_GIT_INCLUDE_STAGED_CODES_NAME); if (StringUtils.isEmptyOrNull(oldRev)) { oldRev = includeStagedCodes ? "HEAD" : "HEAD~"; } String newRev = "HEAD"; DiffCalculator calculator = DiffCalculator.builder().diffAlgorithm(new HistogramDiff()).build(); try { List<DiffEntryWrapper> diffEntryList = calculator.calculateDiff(repoDir, oldRev, newRev, includeStagedCodes) .stream() .filter(diffEntry -> !diffEntry.isDeleted()) .filter(diffEntry -> patternsToExclude.stream() .noneMatch(p -> p.matcher(diffEntry.getNewPath()).matches())) .collect(Collectors.toList()); DIFF_ENTRY_LIST.addAll(diffEntryList); return diffEntryList.stream() .map(DiffEntryWrapper::getNewFile) .collect(Collectors.toList()); } catch (Exception e) { e.printStackTrace(); System.out.println("error happened when calculate git diff"); return Collections.emptyList(); } }
Example 6
Source File: CauseDataHelper.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
private static String retrievePushedBy(final PushHook hook) { String userName = hook.getUserName(); if (!StringUtils.isEmptyOrNull(userName)) { return userName; } final List<Commit> commits = hook.getCommits(); if (commits != null && !commits.isEmpty()) { return commits.get(commits.size() - 1).getAuthor().getName(); } return null; }
Example 7
Source File: GitLabConnection.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public FormValidation doCheckName(@QueryParameter String id, @QueryParameter String value) { if (StringUtils.isEmptyOrNull(value)) { return FormValidation.error(Messages.name_required()); } else { return FormValidation.ok(); } }
Example 8
Source File: GitLabConnection.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public FormValidation doCheckUrl(@QueryParameter String value) { if (StringUtils.isEmptyOrNull(value)) { return FormValidation.error(Messages.url_required()); } else { return FormValidation.ok(); } }
Example 9
Source File: GitLabConnection.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public FormValidation doCheckApiTokenId(@QueryParameter String value) { if (StringUtils.isEmptyOrNull(value)) { return FormValidation.error(Messages.apiToken_required()); } else { return FormValidation.ok(); } }
Example 10
Source File: GitUtils.java From n4js with Eclipse Public License 1.0 | 2 votes |
/** * A helper method for comparing strings. If both of the given strings are empty or <code>null</code>, they are * considered equal. * * @param lhs * the left hand side * @param rhs * the right hand side * @return <code>true</code> if the two strings are to be considered equal and <code>false</code> otherwise */ private static boolean equals(String lhs, String rhs) { if (StringUtils.isEmptyOrNull(lhs) && StringUtils.isEmptyOrNull(rhs)) return true; return Objects.equals(lhs, rhs); }