DefaultColorization implements Colorizer { @Override public String colorize(String message) { if (message == null || "".equals(message)) { return message; } String cleanMessage = stripAnsiCodes(message); if (cleanMessage.contains(BUILD_SUCCESS)) { return cleanMessage.replace(BUILD_SUCCESS, configuration.onBuildSuccess().a(BUILD_SUCCESS).reset().toString()); } if (cleanMessage.contains(BUILD_FAILURE)) { return cleanMessage.replace(BUILD_FAILURE, configuration.onBuildFailure().a(BUILD_FAILURE).reset().toString()); } if (cleanMessage.contains(SUCCESS)) { return cleanMessage.replace(SUCCESS, configuration.onSuccess().a(SUCCESS).reset().toString()); } if (cleanMessage.contains(FAILURE)) { return cleanMessage.replace(FAILURE, configuration.onFailure().a(FAILURE).reset().toString()); } if (cleanMessage.contains(SKIPPED)) { return cleanMessage.replace(SKIPPED, configuration.onSkipped().a(SKIPPED).reset().toString()); } Matcher matcher = PLUGIN_EXECUTION.matcher(cleanMessage); if (matcher.matches()) { return configuration.onPluginExecution().a(matcher.group(1)).reset().toString() + configuration.onPluginExecutionModuleName().a(matcher.group(2)).reset().toString() + configuration.onPluginExecution().a(matcher.group(3)).reset().toString(); } if (isModuleHeader(cleanMessage)) { return configuration.onModuleHeader().a(cleanMessage).reset().toString(); } return cleanMessage; } DefaultColorization();  DefaultColorization(ConfigurableColor configuration);  DefaultColorization(ConfigurableColor configuration, CurrentMavenVersion currentVersion); @Override String colorize(String message);  }
@Test public void should_display_bold_plugin_execution_with_cyan_module_name() throws Exception { String message = "--- maven-surefire-plugin:2.19.1:test (default-test) @ maven-color-log4j2 ---"; assertThat(maven310.colorize(message)).isEqualTo( ansi() .bold() .a("--- maven-surefire-plugin:2.19.1:test (default-test) @ ") .reset().toString() + ansi() .fgBright(CYAN) .bold() .a("maven-color-log4j2") .reset().toString() + ansi() .bold() .a(" ---") .reset() .toString() ); assertThat(maven350.colorize(message)).isEqualTo( ansi() .bold() .a("--- maven-surefire-plugin:2.19.1:test (default-test) @ ") .reset().toString() + ansi() .fgBright(CYAN) .bold() .a("maven-color-log4j2") .reset().toString() + ansi() .bold() .a(" ---") .reset() .toString() ); }
@Test @UseDataProvider("module_header_messages") public void should_display_module_header_in_cyan(String message) throws Exception { assertThat(maven310.colorize(message)) .isEqualTo(ansi().fgBright(CYAN).a(message).reset().toString()); assertThat(maven350.colorize(message)) .isEqualTo(ansi().fgBright(CYAN).a(message).reset().toString()); }
@Test public void should_not_colorize_message_containing_building_without_being_a_module_header() throws Exception { String message = "Building jar: /Users/jcgay/IdeaProjects/maven-color/maven-color-log4j2/target/maven-color-log4j2-0.2-SNAPSHOT.jar"; assertThat(maven310.colorize(message)).isEqualTo(message); assertThat(maven350.colorize(message)).isEqualTo(message); }
@Test @UseDataProvider("success") public void should_display_success_in_green(String message) { assertThat(maven310.colorize(message)).isEqualTo(ansi().fgBright(GREEN).bold().a(message).reset().toString()); assertThat(maven350.colorize(message)).isEqualTo(ansi().fgBright(GREEN).bold().a(message).reset().toString()); }
@Test @UseDataProvider("failure") public void should_display_failure_in_red(String message) { assertThat(maven310.colorize(message)).isEqualTo(ansi().fgBright(RED).bold().a(message).reset().toString()); assertThat(maven350.colorize(message)).isEqualTo(ansi().fgBright(RED).bold().a(message).reset().toString()); }
@Test public void should_display_skipped_in_yellow() { String message = "SKIPPED"; assertThat(maven310.colorize(message)).isEqualTo(ansi().fgBright(YELLOW).bold().a(message).reset().toString()); assertThat(maven350.colorize(message)).isEqualTo(ansi().fgBright(YELLOW).bold().a(message).reset().toString()); }
@Test public void with_recent_maven_version_messages_original_ansi_codes_should_be_stripped() { String message = "\u001B[1m--- \u001B[0;32mmaven-enforcer-plugin:1.4.1:enforce\u001B[0;1m (enforce-maven)\u001B[m @ \u001B[36mmaven-color-logback\u001B[0;1m ---\u001B[m"; assertThat(maven350.colorize(message)).isEqualTo( ansi() .bold() .a("--- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ ") .reset().toString() + ansi() .fgBright(CYAN) .bold() .a("maven-color-logback") .reset().toString() + ansi() .bold() .a(" ---") .reset() .toString() ); }