Skip to content

Commit 928ba89

Browse files
authored
Merge pull request #35 from exadel-inc/develop
[Tech] Release 1.1.2
2 parents c18b7df + 642fdfa commit 928ba89

File tree

19 files changed

+275
-26
lines changed

19 files changed

+275
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ To use Java API, add the following dependency to your Maven project:
9999
<dependency>
100100
<groupId>com.exadel.etoolbox</groupId>
101101
<artifactId>etoolbox-anydiff-core</artifactId>
102-
<version>1.1.1</version> <!-- always prefer the latest stable version -->
102+
<version>1.1.2</version> <!-- always prefer the latest stable version -->
103103
</dependency>
104104
```
105105

cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.exadel.etoolbox</groupId>
99
<artifactId>etoolbox-anydiff</artifactId>
10-
<version>1.1.1</version>
10+
<version>1.1.2</version>
1111
</parent>
1212

1313
<artifactId>etoolbox-anydiff-cli</artifactId>

cli/src/main/java/com/exadel/etoolbox/anydiff/Main.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
@Slf4j
4444
public class Main {
4545

46-
private static final org.slf4j.Marker CONSOLE_ONLY = MarkerFactory.getMarker("CONSOLE_ONLY");
47-
private static final org.slf4j.Marker LOGFILE_ONLY = MarkerFactory.getMarker("FILE_ONLY");
48-
4946
private static final String REPLACED_FILENAME_CHARS = "[.,:/?\"<>|*\\\\]+";
5047

5148
private static final String EXTENSION_HTML = ".html";
@@ -67,7 +64,6 @@ public static void main(String[] args) {
6764
log.info("-{} (--{}) {}", option.getOpt(), option.getLongOpt(), option.getDescription()));
6865
return;
6966
}
70-
System.out.print("EToolbox AnyDiff ");
7167
AnyDiff anyDiff = new AnyDiff()
7268
.left(runArguments.getLeft())
7369
.right(runArguments.getRight());
@@ -194,8 +190,9 @@ private static void printHead(int allCount, long pendingCount) {
194190
log.info(line);
195191
log.info(StringUtils.repeat(Constants.EQUALS, line.length() - 1));
196192
} else {
197-
log.info(String.format("\nFound %d new difference(-s)", pendingCount));
193+
String line = String.format("\nFound %d new difference(-s)", pendingCount);
198194
String secondLine = String.format("There are also %d accepted difference(-s)", allCount - pendingCount);
195+
log.info(line);
199196
log.info(secondLine);
200197
log.info(StringUtils.repeat(Constants.EQUALS, secondLine.length()));
201198
}
@@ -216,11 +213,11 @@ private static void print(Diff diff, RunArguments runArguments, boolean isOneOfM
216213
log.info("No differences");
217214
}
218215
} else {
219-
if (isOneOfMany) {
216+
if (isOneOfMany && diff.getCount() > 0) {
220217
log.info("{} difference(-s)", diff.getCount());
221218
}
222-
log.info(CONSOLE_ONLY, diff.toString(OutputType.CONSOLE));
223-
log.info(LOGFILE_ONLY, diff.toString(OutputType.LOG));
219+
log.info(MarkerFactory.getMarker(Constants.MARKER_CONSOLE_ONLY), diff.toString(OutputType.CONSOLE));
220+
log.info(MarkerFactory.getMarker(Constants.MARKER_FILE_ONLY), diff.toString(OutputType.LOG));
224221
}
225222
}
226223

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License").
3+
* You may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.exadel.etoolbox.anydiff.log;
15+
16+
import ch.qos.logback.classic.spi.ILoggingEvent;
17+
import ch.qos.logback.classic.spi.LoggingEvent;
18+
import com.exadel.etoolbox.anydiff.Constants;
19+
import org.apache.commons.lang3.StringUtils;
20+
21+
import java.io.IOException;
22+
23+
/**
24+
* Extends {@link ch.qos.logback.core.ConsoleAppender} to handle both transient (disappearing) and persistent console
25+
* messages
26+
*/
27+
public class ConsoleAppender extends ch.qos.logback.core.ConsoleAppender<ILoggingEvent> {
28+
29+
private int transientMessageLength = 0;
30+
31+
@Override
32+
protected void writeOut(ILoggingEvent event) throws IOException {
33+
if (!(event instanceof LoggingEvent)) {
34+
super.writeOut(event);
35+
return;
36+
}
37+
if (transientMessageLength > 0) {
38+
LoggingEvent newEvent = new LoggingEvent();
39+
newEvent.setMessage("." + StringUtils.repeat('\b', transientMessageLength));
40+
super.writeOut(newEvent);
41+
transientMessageLength = 0;
42+
}
43+
if (StringUtils.startsWith(event.getMessage(), Constants.DOT)) {
44+
transientMessageLength = event.getFormattedMessage().length() - 1;
45+
}
46+
super.writeOut(event);
47+
}
48+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License").
3+
* You may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.exadel.etoolbox.anydiff.log;
15+
16+
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
17+
import ch.qos.logback.classic.spi.ILoggingEvent;
18+
import com.exadel.etoolbox.anydiff.Constants;
19+
import org.apache.commons.lang3.StringUtils;
20+
21+
/**
22+
* Extends {@link PatternLayoutEncoder} to handle both transient and persistent console messages
23+
*/
24+
public class ConsoleEncoder extends PatternLayoutEncoder {
25+
26+
@Override
27+
public byte[] encode(ILoggingEvent event) {
28+
if (StringUtils.startsWith(event.getMessage(), Constants.DOT)) {
29+
return event.getFormattedMessage().substring(Constants.DOT.length()).getBytes();
30+
}
31+
return super.encode(event);
32+
}
33+
}

cli/src/main/java/com/exadel/etoolbox/anydiff/log/FileAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* Extends {@link ch.qos.logback.core.FileAppender} to provide a custom log file cleanup logic
25-
* @param <E>
25+
* @param <E> Type of log event
2626
*/
2727
public class FileAppender<E> extends ch.qos.logback.core.FileAppender<E> {
2828

cli/src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<configuration>
33
<timestamp key="timestamp" datePattern="yyyyMMddHHmmss"/>
44

5-
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<appender name="CONSOLE" class="com.exadel.etoolbox.anydiff.log.ConsoleAppender">
66
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
77
<evaluator class="com.exadel.etoolbox.anydiff.log.ExcludingEventEvaluator">
88
<exclude>FILE_ONLY</exclude>
@@ -12,7 +12,7 @@
1212
<OnMismatch>DENY</OnMismatch>
1313
<OnMatch>ACCEPT</OnMatch>
1414
</filter>
15-
<encoder>
15+
<encoder class="com.exadel.etoolbox.anydiff.log.ConsoleEncoder">
1616
<charset>UTF-8</charset>
1717
<pattern>%msg%n</pattern>
1818
</encoder>

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.exadel.etoolbox</groupId>
99
<artifactId>etoolbox-anydiff</artifactId>
10-
<version>1.1.1</version>
10+
<version>1.1.2</version>
1111
</parent>
1212

1313
<artifactId>etoolbox-anydiff-core</artifactId>

core/src/main/java/com/exadel/etoolbox/anydiff/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class Constants {
6464
public static final char BRACKET_OPEN = '[';
6565
public static final char BRACKET_CLOSE = ']';
6666

67+
public static final String MARKER_CONSOLE_ONLY = "CONSOLE_ONLY";
68+
public static final String MARKER_FILE_ONLY = "FILE_ONLY";
69+
6770
public static final String TAG_AUTO_CLOSE = "/>";
6871
public static final String TAG_CLOSE = ">";
6972
public static final char TAG_CLOSE_CHAR = '>';

core/src/main/java/com/exadel/etoolbox/anydiff/ContentType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ boolean matchesName(String value) {
9090
String extension = StringUtils.substringAfterLast(value, Constants.DOT);
9191
return StringUtils.equalsAnyIgnoreCase(
9292
extension,
93+
"any",
94+
"conf",
9395
"css",
9496
"csv",
9597
"ecma",
@@ -104,8 +106,11 @@ boolean matchesName(String value) {
104106
"mf",
105107
"php",
106108
"properties",
109+
"rules",
107110
"ts",
108-
"txt");
111+
"txt",
112+
"vars",
113+
"vhost");
109114
}
110115
};
111116

0 commit comments

Comments
 (0)