Skip to content

Commit f0ac8d5

Browse files
committed
Update dockerfile + don't write non-modified file
1 parent b6d2f69 commit f0ac8d5

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,6 @@ gradle-app.setting
152152
# End of https://www.toptal.com/developers/gitignore/api/gradle,java,intellij
153153

154154
.idea/
155+
156+
### MacOS ###
157+
.DS_Store

Diff for: Dockerfile

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM adoptopenjdk/openjdk11:alpine-jre
2-
RUN mkdir /opt/app
3-
COPY build/distributions/marlin-console-configurator.zip /opt/app
4-
RUN tar xvf /opt/app/marlin-console-configurator.zip -C /opt/app
5-
RUN chmod +x /opt/app/bin/marlin-console-configurator
6-
CMD ["/opt/app/bin/marlin-console-configurator"]
2+
ADD build/bootScripts/* /app/bin/
3+
ADD build/libs/* /app/lib/
4+
WORKDIR /app/files
5+
CMD ["/app/bin/marlin-console-configurator"]

Diff for: src/main/java/fr/chuckame/marlinfw/configurator/command/ApplyCommand.java

+25-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import reactor.core.publisher.Flux;
1616
import reactor.core.publisher.Mono;
1717
import reactor.util.function.Tuple2;
18+
import reactor.util.function.Tuples;
1819

1920
import java.nio.file.Path;
2021
import java.util.Collection;
@@ -49,17 +50,29 @@ public Mono<Void> run() {
4950
return profilePropertiesParser.parseFromFile(profilePath)
5051
.map(changeAdapter::profileToConstants)
5152
.flatMap(wantedConstants ->
52-
prepareChanges(filesPath, wantedConstants)
53+
prepareChanges(wantedConstants)
5354
.flatMap(changes -> printChanges(changes)
5455
.then(printUnusedConstants(changes, wantedConstants))
5556
.then(doSave ? checkIfUserAgree().then(applyAndSaveChanges(changes)) : Mono.empty()))
5657
);
5758
}
5859

60+
public Mono<Map<Path, List<LineChange>>> prepareChanges(final Map<String, Constant> wantedConstants) {
61+
return fileHelper.listFiles(filesPath)
62+
.flatMap(filePath -> fileHelper.lines(filePath)
63+
.index()
64+
.concatMap(line -> lineChangeManager.prepareChange(line.getT2(), line.getT1().intValue(), wantedConstants))
65+
.collectList()
66+
.filter(changes -> changes.stream().anyMatch(LineChange::isConstant))
67+
.map(changes -> Tuples.of(filePath, changes)))
68+
.collectMap(Tuple2::getT1, Tuple2::getT2);
69+
}
70+
5971
private Mono<Void> printChanges(final Map<Path, List<LineChange>> changes) {
6072
return Flux.fromIterable(changes.entrySet())
6173
.concatMap(fileChanges -> Flux.concat(
62-
Flux.just(String.format("%s change(s) for file %s:", fileChanges.getValue().size(), fileChanges.getKey())),
74+
Flux.just(String.format("%s change(s) to apply for file %s:", fileChanges.getValue().stream().filter(this::isModifyingChange).count(), fileChanges
75+
.getKey())),
6376
Flux.fromIterable(fileChanges.getValue()).filter(LineChange::isConstant).map(lineChangeFormatter::format),
6477
Flux.just("")
6578
))
@@ -72,7 +85,7 @@ private Mono<Void> printUnusedConstants(final Map<Path, List<LineChange>> change
7285
return lineChangeManager.getUnusedWantedConstants(changes.values().stream().flatMap(List::stream).collect(Collectors.toList()), wantedConstants)
7386
.collectList()
7487
.filter(Predicate.not(List::isEmpty))
75-
.doOnNext(unusedConstants -> consoleHelper.writeLine(String.format("Still some unused constants: %s%n", unusedConstants)))
88+
.doOnNext(unusedConstants -> consoleHelper.writeLine(String.format("Still some unused constants: %s", unusedConstants)))
7689
.then();
7790
}
7891

@@ -87,23 +100,22 @@ private Mono<Void> checkIfUserAgree() {
87100
.then();
88101
}
89102

90-
public Mono<Map<Path, List<LineChange>>> prepareChanges(final List<Path> filesPath, final Map<String, Constant> wantedConstants) {
91-
return fileHelper.listFiles(filesPath)
92-
.flatMap(filePath -> fileHelper.lines(filePath)
93-
.index()
94-
.concatMap(line -> lineChangeManager.prepareChange(line.getT2(), line.getT1().intValue(), wantedConstants))
95-
.collectList()
96-
.zipWith(Mono.just(filePath)))
97-
.collectMap(Tuple2::getT2, Tuple2::getT1);
98-
}
99-
100103
public Mono<Void> applyAndSaveChanges(final Map<Path, List<LineChange>> changes) {
101104
return Flux.fromIterable(changes.entrySet())
105+
.filter(e -> onlyChangedFile(e.getValue()))
102106
.groupBy(Map.Entry::getKey, Map.Entry::getValue)
103107
.flatMap(fileChanges -> fileHelper.write(fileChanges.key(), true, fileChanges.flatMap(this::applyChanges)))
104108
.then();
105109
}
106110

111+
private boolean onlyChangedFile(final List<LineChange> changes) {
112+
return changes.stream().anyMatch(this::isModifyingChange);
113+
}
114+
115+
private boolean isModifyingChange(final LineChange change) {
116+
return !LineChange.DiffEnum.DO_NOTHING.equals(change.getDiff());
117+
}
118+
107119
public Flux<String> applyChanges(final Collection<LineChange> changes) {
108120
return Flux.fromIterable(changes).flatMap(lineChangeManager::applyChange);
109121
}

Diff for: src/main/java/fr/chuckame/marlinfw/configurator/command/CommandRunner.java

+13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
import com.beust.jcommander.ParameterException;
55
import fr.chuckame.marlinfw.configurator.util.ConsoleHelper;
66
import lombok.RequiredArgsConstructor;
7+
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.boot.CommandLineRunner;
89
import org.springframework.stereotype.Component;
910

11+
import java.nio.file.NoSuchFileException;
12+
import java.nio.file.Path;
13+
14+
@Slf4j
1015
@Component
1116
@RequiredArgsConstructor
1217
public class CommandRunner implements CommandLineRunner {
@@ -20,6 +25,14 @@ public void run(final String[] args) throws Exception {
2025
} catch (final ManuallyStoppedException e) {
2126
consoleHelper.writeErrorLine(e.getMessage());
2227
System.exit(e.getExitCode());
28+
} catch (final Exception e) {
29+
if (e.getCause() instanceof NoSuchFileException) {
30+
consoleHelper.writeErrorLine("File not found: " + Path.of(e.getCause().getMessage()).toAbsolutePath());
31+
System.exit(4);
32+
} else {
33+
consoleHelper.writeErrorLine(e.getMessage());
34+
System.exit(5);
35+
}
2336
}
2437
}
2538

0 commit comments

Comments
 (0)