@Override public void visit(TextNode node) { if (this.pages < 2 && StringUtils.isEmptyOrNull(this.title)) { this.title = node.getText(); } super.visit(node); }
/** * Obtain an integer value from the configuration. * * @param section section the key is grouped within. * @param subsection subsection name, such a remote or branch name. * @param name name of the key to get. * @param defaultValue default value to return if no value was present. * @return an integer value from the configuration, or defaultValue. */ public long getLong( final String section, String subsection, final String name, final long defaultValue) { final String str = getString(section, subsection, name); if (str == null) return defaultValue; String n = str.trim(); if (n.length() == 0) return defaultValue; long mul = 1; switch (StringUtils.toLowerCase(n.charAt(n.length() - 1))) { case 'g': mul = GiB; break; case 'm': mul = MiB; break; case 'k': mul = KiB; break; } if (mul > 1) n = n.substring(0, n.length() - 1).trim(); if (n.length() == 0) return defaultValue; try { return mul * Long.parseLong(n); } catch (NumberFormatException nfe) { throw new IllegalArgumentException( MessageFormat.format(JGitText.get().invalidIntegerValue, section, name, str)); } }
@Override public boolean contains(Object needle) { if (!(needle instanceof String)) return false; String n = (String) needle; return names.containsKey(n) || names.containsKey(StringUtils.toLowerCase(n)); }
public Set<String> parse(Config cfg) { final Map<String, String> m = new LinkedHashMap<String, String>(); while (cfg != null) { for (final Entry e : cfg.state.get().entryList) { if (e.name == null) continue; if (!StringUtils.equalsIgnoreCase(section, e.section)) continue; if ((subsection == null && e.subsection == null) || (subsection != null && subsection.equals(e.subsection))) { String lc = StringUtils.toLowerCase(e.name); if (!m.containsKey(lc)) m.put(lc, e.name); } } cfg = cfg.baseConfig; } return new CaseFoldingSet(m); }
/** * Clones secured git remote repository to the file system. * * @param gitDirectory where the remote repository will be cloned * @param repositoryURI repository's URI example: https://qwerty.com/xyz/abc.git * @param username the username used for authentication * @param password the password used for authentication * @throws InvalidRemoteException * @throws TransportException * @throws GitAPIException */ public static void cloneRepository( File gitDirectory, String repositoryURI, String username, String password) throws InvalidRemoteException, TransportException, GitAPIException { try { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repositoryURI); if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) { cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(username, password)); } cloneCommand.setRemote(Constants.DEFAULT_REMOTE_NAME); cloneCommand.setDirectory(gitDirectory); cloneCommand.call(); } catch (NullPointerException e) { throw new TransportException(INVALID_USERNAME_AND_PASSWORD); } }
private static boolean getBoolean(ServletConfig cfg, String param) throws ServletException { String n = cfg.getInitParameter(param); if (n == null) return false; try { return StringUtils.toBoolean(n); } catch (IllegalArgumentException err) { throw new ServletException( MessageFormat.format(HttpServerText.get().invalidBoolean, param, n)); } }
/** * Parse the commit message and return the first "line" of it. * * <p>The first line is everything up to the first pair of LFs. This is the "oneline" format, * suitable for output in a single line display. * * <p>This method parses and returns the message portion of the commit buffer, after taking the * commit's character set into account and decoding the buffer using that character set. This * method is a fairly expensive operation and produces a new string on each invocation. * * @return decoded commit message as a string. Never null. The returned string does not contain * any LFs, even if the first paragraph spanned multiple lines. Embedded LFs are converted to * spaces. */ public final String getShortMessage() { final byte[] raw = buffer; final int msgB = RawParseUtils.commitMessage(raw, 0); if (msgB < 0) return ""; // $NON-NLS-1$ final Charset enc = RawParseUtils.parseEncoding(raw); final int msgE = RawParseUtils.endOfParagraph(raw, msgB); String str = RawParseUtils.decode(enc, raw, msgB, msgE); if (hasLF(raw, msgB, msgE)) str = StringUtils.replaceLineBreaksWithSpace(str); return str; }
/** * Get a boolean value from the git config * * @param section section the key is grouped within. * @param subsection subsection name, such a remote or branch name. * @param name name of the key to get. * @param defaultValue default value to return if no value was present. * @return true if any value or defaultValue is true, false for missing or explicit false */ public boolean getBoolean( final String section, String subsection, final String name, final boolean defaultValue) { String n = getRawString(section, subsection, name); if (n == null) return defaultValue; if (MAGIC_EMPTY_VALUE == n) return true; try { return StringUtils.toBoolean(n); } catch (IllegalArgumentException err) { throw new IllegalArgumentException( MessageFormat.format(JGitText.get().invalidBooleanValue, section, name, n)); } }
public Set<String> parse(Config cfg) { final Set<String> result = new LinkedHashSet<String>(); while (cfg != null) { for (final Entry e : cfg.state.get().entryList) { if (e.subsection != null && e.name == null && StringUtils.equalsIgnoreCase(section, e.section)) result.add(e.subsection); } cfg = cfg.baseConfig; } return Collections.unmodifiableSet(result); }
public Set<String> parse(Config cfg) { final Map<String, String> m = new LinkedHashMap<String, String>(); while (cfg != null) { for (final Entry e : cfg.state.get().entryList) { if (e.section != null) { String lc = StringUtils.toLowerCase(e.section); if (!m.containsKey(lc)) m.put(lc, e.section); } } cfg = cfg.baseConfig; } return new CaseFoldingSet(m); }
/** * Parse an enumeration from the configuration. * * @param <T> type of the enumeration object. * @param all all possible values in the enumeration which should be recognized. Typically {@code * EnumType.values()}. * @param section section the key is grouped within. * @param subsection subsection name, such a remote or branch name. * @param name name of the key to get. * @param defaultValue default value to return if no value was present. * @return the selected enumeration value, or {@code defaultValue}. */ public <T extends Enum<?>> T getEnum( final T[] all, final String section, final String subsection, final String name, final T defaultValue) { String value = getString(section, subsection, name); if (value == null) return defaultValue; String n = value.replace(' ', '_'); T trueState = null; T falseState = null; for (T e : all) { if (StringUtils.equalsIgnoreCase(e.name(), n)) return e; else if (StringUtils.equalsIgnoreCase(e.name(), "TRUE")) trueState = e; else if (StringUtils.equalsIgnoreCase(e.name(), "FALSE")) falseState = e; } // This is an odd little fallback. C Git sometimes allows boolean // values in a tri-state with other things. If we have both a true // and a false value in our enumeration, assume its one of those. // if (trueState != null && falseState != null) { try { return StringUtils.toBoolean(n) ? trueState : falseState; } catch (IllegalArgumentException err) { // Fall through and use our custom error below. } } if (subsection != null) throw new IllegalArgumentException( MessageFormat.format(JGitText.get().enumValueNotSupported3, section, name, value)); else throw new IllegalArgumentException( MessageFormat.format(JGitText.get().enumValueNotSupported2, section, name, value)); }
/** * find out which branch that specified commit come from. * * @param commit * @return branch name. * @throws GitException */ public String getBranchName(RevCommit commit) throws GitException { Set<Entry<String, Ref>> refs = repository.getAllRefs().entrySet(); if (this.masterRef == null) { this.masterRef = this.findMasterRef(); } boolean commitBelongsToBranch; boolean commitBelongsToMaster; List<String> foundInBranches = new ArrayList<String>(); try { RevWalk walker = new RevWalk(this.repository); RevCommit targetCommit = walker.parseCommit(this.repository.resolve(commit.getName())); for (Entry<String, Ref> ref : refs) { if (ref.getKey().startsWith(Constants.R_HEADS) && !ref.getKey().equals(this.masterRef)) { commitBelongsToBranch = walker.isMergedInto(targetCommit, walker.parseCommit(ref.getValue().getObjectId())); commitBelongsToMaster = false; if (this.masterRef != null) { commitBelongsToMaster = walker.isMergedInto(targetCommit, walker.parseCommit(this.masterRef.getObjectId())); } if (commitBelongsToBranch && !commitBelongsToMaster) { foundInBranches.add(ref.getValue().getName()); } } } } catch (GitException | MissingObjectException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IncorrectObjectTypeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (foundInBranches.size() == 0) { return "master"; } return StringUtils.join(foundInBranches, ", "); }
private static boolean eqIgnoreCase(final String a, final String b) { if (a == null && b == null) return true; if (a == null || b == null) return false; return StringUtils.equalsIgnoreCase(a, b); }
/** * Join a collection of Strings together using the specified separator. * * @param parts Strings to join * @param separator used to join * @return a String with all the joined parts */ public static String join(Collection<String> parts, String separator) { return StringUtils.join(parts, separator, separator); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces("text/plain") public String deploy( DeployRequest req, @HeaderParam("Authorization") @DefaultValue("no token") String auth, @Context ServletContext context) throws Exception { if (!this.isAuth(auth)) { throw new Exception("Unauthorized!"); } String contextRoot = req.getContextRoot(); String artifact = req.getArtifact(); if (StringUtils.isEmptyOrNull(req.getRepo()) || StringUtils.isEmptyOrNull(req.getDomain())) { return "Error: missing repo and/or domain."; } if (StringUtils.isEmptyOrNull(contextRoot)) { contextRoot = "/"; } if (StringUtils.isEmptyOrNull(artifact)) { artifact = "com.meltmedia.cadmium:cadmium-war:war:" + version; } if (StringUtils.isEmptyOrNull(req.getConfigRepo())) { req.setConfigRepo(req.getRepo()); } if (StringUtils.isEmptyOrNull(req.getConfigBranch())) { req.setConfigBranch("master"); } if (StringUtils.isEmptyOrNull(req.getBranch())) { req.setBranch("master"); } ChannelMember coordinator = membershipTracker.getCoordinator(); com.meltmedia.cadmium.deployer.DeployRequest mRequest = new com.meltmedia.cadmium.deployer.DeployRequest(); mRequest.setBranch(req.getBranch()); mRequest.setRepo(req.getRepo()); mRequest.setConfigBranch(req.getConfigBranch()); mRequest.setConfigRepo(req.getConfigRepo()); mRequest.setDomain(req.getDomain()); mRequest.setContext(contextRoot); mRequest.setSecure(!req.isDisableSecurity()); mRequest.setArtifact(artifact); Message<com.meltmedia.cadmium.deployer.DeployRequest> msg = new Message<com.meltmedia.cadmium.deployer.DeployRequest>( DeployCommandAction.DEPLOY_ACTION, mRequest); response.reset(coordinator); sender.sendMessage(msg, coordinator); int timeout = 4800; while (timeout-- > 0) { Thread.sleep(500l); Message<DeployResponse> returnMsg = response.getResponse(coordinator); if (returnMsg != null) { if (returnMsg.getBody().getError() != null) { throw new Exception(returnMsg.getBody().getError()); } return returnMsg.getBody().getWarName(); } } return "ok"; }
private static final byte lc(final byte q) { return (byte) StringUtils.toLowerCase((char) (q & 0xff)); }