diff --git a/src/main/java/io/fabric8/maven/docker/service/WatchService.java b/src/main/java/io/fabric8/maven/docker/service/WatchService.java index 3af214a16..d750894b0 100644 --- a/src/main/java/io/fabric8/maven/docker/service/WatchService.java +++ b/src/main/java/io/fabric8/maven/docker/service/WatchService.java @@ -58,7 +58,7 @@ public WatchService(ArchiveService archiveService, BuildService buildService, Do public synchronized void watch(WatchContext context, BuildService.BuildContext buildContext, List 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(); @@ -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 ")); } } @@ -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 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 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()); } } }; @@ -168,7 +165,7 @@ private Runnable createBuildWatchTask(final ImageWatcher watcher, @Override public void run() { List 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);