AndroidGradlePluginOutputParser implements BuildOutputParser { @Override public boolean parse(String line, BuildOutputInstantReader reader, Consumer<? super BuildEvent> messageConsumer) { if (WARNING_PREFIX.regionMatches(true, 0, line, 0, WARNING_PREFIX.length())) { String message = line.substring(WARNING_PREFIX.length()).trim(); messageConsumer .accept( new MessageEventImpl(reader.getParentEventId(), MessageEvent.Kind.WARNING, ANDROID_GRADLE_PLUGIN_MESSAGES_GROUP, message, message)); return true; } if (ERROR_PREFIX.regionMatches(true, 0, line, 0, ERROR_PREFIX.length())) { String message = line.substring(ERROR_PREFIX.length()).trim(); messageConsumer .accept(new MessageEventImpl(reader.getParentEventId(), MessageEvent.Kind.ERROR, ANDROID_GRADLE_PLUGIN_MESSAGES_GROUP, message, message)); return true; } return false; }  @Override boolean parse(String line, BuildOutputInstantReader reader, Consumer<? super BuildEvent> messageConsumer);  }
@Test public void testParseWarningFromOutput() { String line = "WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation'."; String expected = "Configuration 'compile' is obsolete and has been replaced with 'implementation'."; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); ArgumentCaptor<MessageEvent> messageCaptor = ArgumentCaptor.forClass(MessageEvent.class); assertTrue(myParser.parse(line, myReader, myConsumer)); verify(myConsumer).accept(messageCaptor.capture()); List<MessageEvent> generatedMessages = messageCaptor.getAllValues(); assertThat(generatedMessages).hasSize(1); assertThat(generatedMessages.get(0)).isInstanceOf(MessageEventImpl.class); MessageEventImpl fileMessageEvent = (MessageEventImpl)generatedMessages.get(0); assertThat(fileMessageEvent.getResult().getDetails()).isEqualTo(expected); }
@Test public void testParseJavacWithSource() { String line = "MyClass.java:38: warning: [serial] serializable class MyClass has no definition of serialVersionUID"; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); assertFalse(myParser.parse(line, myReader, myConsumer)); }
@Test public void testParseJavacWithoutSource() { String line = "warning: [serial] serializable class MyClass has no definition of serialVersionUID"; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); assertTrue(myParser.parse(line, myReader, myConsumer)); }
@Test public void testParseAGPResourceWarning() { String line = "warning: string 'snowball' has no default translation.\n"; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); assertTrue(myParser.parse(line, myReader, myConsumer)); }
@Test public void testParseAGPError() { String line = "ERROR: Something went wrong!\n"; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); assertTrue(myParser.parse(line, myReader, myConsumer)); }
@Test public void testParseJavaError() { String line = "MyClass.java:23 error: Something went REALLY wrong!\n"; when(myReader.getParentEventId()).thenReturn("BUILD_ID_MOCK"); assertFalse(myParser.parse(line, myReader, myConsumer)); }