Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: WatchService : Anonymous new Runnable() can be replaced with lambda #1783

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/main/java/io/fabric8/maven/docker/service/WatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public WatchService(ArchiveService archiveService, BuildService buildService, Do
public synchronized void watch(WatchContext context, BuildService.BuildContext buildContext, List<ImageConfiguration> images) throws DockerAccessException,
MojoExecutionException {

// Important to be be a single threaded scheduler since watch jobs must run serialized
// Important to be a single threaded scheduler since watch jobs must run serialized
ScheduledExecutorService executor = null;
try {
executor = Executors.newSingleThreadScheduledExecutor();
Expand Down Expand Up @@ -97,7 +97,7 @@ public synchronized void watch(WatchContext context, BuildService.BuildContext b
tasks.add("restarting");
}

if (tasks.size() > 0) {
if (!tasks.isEmpty()) {
log.info("%s: Watch for %s", imageConfig.getDescription(), StringUtils.join(tasks.toArray(), " and "));
}
}
Expand Down Expand Up @@ -125,22 +125,19 @@ private Runnable createCopyWatchTask(final ImageWatcher watcher,
final ImageConfiguration imageConfig = watcher.getImageConfiguration();

final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, assemblyName, mojoParameters);
return new Runnable() {
@Override
public void run() {
List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
if (entries != null && entries.size() > 0) {
try {
log.info("%s: Assembly %s changed. Copying changed files to container ...", imageConfig.getDescription(), assemblyName);

File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(),
imageConfig.getName(), mojoParameters);
dockerAccess.copyArchiveToContainer(watcher.getContainerId(), changedFilesArchive, containerBaseDir);
callPostExec(watcher);
} catch (MojoExecutionException | IOException | ExecException e) {
log.error("%s: Error when copying files to container %s: %s",
imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
}
return () -> {
List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
if (entries != null && !entries.isEmpty()) {
try {
log.info("%s: Assembly %s changed. Copying changed files to container ...", imageConfig.getDescription(), assemblyName);

File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(),
imageConfig.getName(), mojoParameters);
dockerAccess.copyArchiveToContainer(watcher.getContainerId(), changedFilesArchive, containerBaseDir);
callPostExec(watcher);
} catch (MojoExecutionException | IOException | ExecException e) {
log.error("%s: Error when copying files to container %s: %s",
imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
}
}
};
Expand Down Expand Up @@ -168,7 +165,7 @@ private Runnable createBuildWatchTask(final ImageWatcher watcher,
@Override
public void run() {
List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
if (entries != null && entries.size() > 0) {
if (entries != null && !entries.isEmpty()) {
try {
log.info("%s: Assembly %s changed. Rebuild ...", imageConfig.getDescription(), assemblyName);

Expand Down
Loading