@Test public void shouldParseOpenGrokTagsLog() throws IOException { final byte[] OGK_LOG_BYTES = OGK_LOG.getBytes(StandardCharsets.UTF_8); ByteArrayInputStream bytesIn = new ByteArrayInputStream(OGK_LOG_BYTES); TreeSet<TagEntry> tagList = new TreeSet<>(); GitTagParser parser = new GitTagParser(tagList); parser.processStream(bytesIn); long countLF = OGK_LOG.chars().filter(ch -> ch == '\n').count(); assertEquals("size should == LF count - 1", countLF - 1, tagList.size()); GitTagEntry t1 = new GitTagEntry("c6963a7ea2753672325502d342e653700be550a8", new Date(1377876557_000L), "0.12-rc1"); assertTrue("should contain entry matching t1", tagList.contains(t1)); TagEntry floor1 = tagList.floor(t1); assertNotNull("should find floor() given contains() is true", floor1); assertEquals("tags should equal", t1.tags, floor1.tags); assertEquals("hashes should equal", t1.getHash(), ((GitTagEntry) floor1).getHash()); GitTagEntry t2 = new GitTagEntry("6d454cfc137241865a8639a2b1ed64dea81a448b", new Date(1538750353_000L), "1.1-rc45, 1.1-rc44"); assertTrue("should contain entry matching t2", tagList.contains(t2)); TagEntry floor2 = tagList.floor(t2); assertNotNull("should find floor() given contains() is true", floor2); assertEquals("tags should equal", t2.tags, floor2.tags); assertEquals("hashes should equal", t2.getHash(), ((GitTagEntry) floor2).getHash()); }
@Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); @Override void processStream(InputStream input); }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); @Override void processStream(InputStream input);  }