#29 - Workspace.LineCallback now uses Optional as return type.
That allows us to replace non-null checks with a simple ….ifPresent(…).
This commit is contained in:
@@ -30,6 +30,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -190,12 +191,7 @@ public class Workspace {
|
|||||||
long number = 0;
|
long number = 0;
|
||||||
|
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
|
callback.doWith(scanner.nextLine(), number++).ifPresent(it -> builder.append(it).append("\n"));
|
||||||
String result = callback.doWith(scanner.nextLine(), number++);
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
builder.append(result).append("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeContentToFile(filename, project, builder.toString());
|
writeContentToFile(filename, project, builder.toString());
|
||||||
@@ -229,6 +225,6 @@ public class Workspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface LineCallback {
|
public interface LineCallback {
|
||||||
String doWith(String line, long number);
|
Optional<String> doWith(String line, long number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.release.git.GitOperations;
|
import org.springframework.data.release.git.GitOperations;
|
||||||
@@ -83,9 +84,9 @@ public class ReleaseOperations {
|
|||||||
builder.append(line).append("\n\n");
|
builder.append(line).append("\n\n");
|
||||||
builder.append(changelog.toString());
|
builder.append(changelog.toString());
|
||||||
|
|
||||||
return builder.toString();
|
return Optional.of(builder.toString());
|
||||||
} else {
|
} else {
|
||||||
return line;
|
return Optional.of(line);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ public class ReleaseOperations {
|
|||||||
iteration.stream().forEach(module -> {
|
iteration.stream().forEach(module -> {
|
||||||
|
|
||||||
boolean processed = workspace.processFile("src/main/resources/notice.txt", module.getProject(),
|
boolean processed = workspace.processFile("src/main/resources/notice.txt", module.getProject(),
|
||||||
(line, number) -> number != 0 ? line : module.toString());
|
(line, number) -> Optional.of(number != 0 ? line : module.toString()));
|
||||||
|
|
||||||
if (processed) {
|
if (processed) {
|
||||||
logger.log(module, "Updated notice.txt.");
|
logger.log(module, "Updated notice.txt.");
|
||||||
|
|||||||
Reference in New Issue
Block a user