Skip to content

Commit

Permalink
Fix watch warn displayed many times
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Sep 2, 2024
1 parent 9aeee01 commit 1fdaf6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -39,7 +40,7 @@
class BundleWebAssetsScannerProcessor {

private static final Logger LOGGER = Logger.getLogger(BundleWebAssetsScannerProcessor.class);

public static AtomicBoolean enableBundlingWatch = new AtomicBoolean(true);
private static final String FEATURE = "web-bundler";
public static final String MAIN_ENTRYPOINT_KEY = "main";

Expand Down Expand Up @@ -97,7 +98,9 @@ void collect(ProjectResourcesScannerBuildItem scanner,
produceWebAssets(bundles, quteTagsAssets, bundleConfigAssets, devContext, true);
return;
}

LOGGER.debug("Web bundler scan started");
enableBundlingWatch.set(true);
final List<Scanner> quteTagsAssetsScanners = new ArrayList<>();
final List<Scanner> bundleConfigAssetsScanners = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkiverse.web.bundler.deployment;

import static io.quarkiverse.web.bundler.deployment.BundleWebAssetsScannerProcessor.MAIN_ENTRYPOINT_KEY;
import static io.quarkiverse.web.bundler.deployment.BundleWebAssetsScannerProcessor.enableBundlingWatch;
import static io.quarkiverse.web.bundler.deployment.items.BundleWebAsset.BundleType.MANUAL;
import static io.quarkiverse.web.bundler.deployment.util.PathUtils.join;
import static io.quarkiverse.web.bundler.deployment.web.GeneratedWebResourcesProcessor.WEB_BUNDLER_LIVE_RELOAD_PATH;
Expand Down Expand Up @@ -37,8 +38,6 @@
public class PrepareForBundlingProcessor {

private static final Logger LOGGER = Logger.getLogger(PrepareForBundlingProcessor.class);
public static volatile boolean enableBundlingWatch = true;

private static final Map<EsBuildConfig.Loader, Function<LoadersConfig, Optional<Set<String>>>> LOADER_CONFIGS = Map
.ofEntries(
entry(EsBuildConfig.Loader.JS, LoadersConfig::js),
Expand Down Expand Up @@ -122,7 +121,7 @@ ReadyForBundlingBuildItem prepareForBundling(WebBundlerConfig config,
&& entryPoints.stream().map(EntryPointBuildItem::getWebAssets).flatMap(List::stream)
.map(WebAsset::resourceName)
.noneMatch(liveReload.getChangedResources()::contains)) {
if (config.browserLiveReload() && enableBundlingWatch) {
if (config.browserLiveReload() && enableBundlingWatch.get()) {
// We need to set non-restart watched file again
for (EntryPointBuildItem entryPoint : entryPoints) {
for (BundleWebAsset webAsset : entryPoint.getWebAssets()) {
Expand All @@ -136,9 +135,8 @@ ReadyForBundlingBuildItem prepareForBundling(WebBundlerConfig config,
}
}
return new ReadyForBundlingBuildItem(prepareForBundlingContext.bundleOptions(), null, targetDir.dist(),
enableBundlingWatch);
enableBundlingWatch.get());
}
enableBundlingWatch = true;

try {
Files.createDirectories(targetDir.webBundler());
Expand Down Expand Up @@ -242,7 +240,7 @@ ReadyForBundlingBuildItem prepareForBundling(WebBundlerConfig config,
final BundleOptions options = optionsBuilder.build();
liveReload.setContextObject(PrepareForBundlingContext.class,
new PrepareForBundlingContext(config, installedWebDependencies.list(), entryPoints, options));
return new ReadyForBundlingBuildItem(options, started, targetDir.dist(), enableBundlingWatch);
return new ReadyForBundlingBuildItem(options, started, targetDir.dist(), enableBundlingWatch.get());
} catch (IOException e) {
liveReload.setContextObject(PrepareForBundlingContext.class, new PrepareForBundlingContext());
throw new UncheckedIOException(e);
Expand All @@ -256,7 +254,7 @@ static void createAsset(BuildProducer<HotDeploymentWatchedFileBuildItem> watched
Files.write(targetPath, webAsset.resource().content(), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
} else {
if (browserLiveReload && enableBundlingWatch) {
if (browserLiveReload && enableBundlingWatch.get()) {
createSymbolicLinkOrFallback(watchedFiles, webAsset, targetPath);
} else {
Files.copy(webAsset.resource().path(), targetPath, StandardCopyOption.REPLACE_EXISTING);
Expand All @@ -278,15 +276,18 @@ static void createSymbolicLinkOrFallback(BuildProducer<HotDeploymentWatchedFileB
.setLocation(webAsset.resourceName())
.build());
} catch (FileSystemException e) {
enableBundlingWatch = false;
LOGGER.warn(
"Creating a symbolic link was not authorized on this system. It is required by the Web Bundler to allow filesystem watch. As a result, Web Bundler live-reload will use a scheduler as a fallback.\n\nTo resolve this issue, please add the necessary permissions to allow symbolic link creation.");
if (enableBundlingWatch.getAndSet(false)) {
LOGGER.warn(
"Creating a symbolic link was not authorized on this system. It is required by the Web Bundler to allow filesystem watch. As a result, Web Bundler live-reload will use a scheduler as a fallback.\n\nTo resolve this issue, please add the necessary permissions to allow symbolic link creation.");
}

Files.copy(webAsset.resource().path(), targetPath, StandardCopyOption.REPLACE_EXISTING);
}
} else {
LOGGER.warn(
"The sources are necessary by the Web Bundler to allow filesystem watch. Web Bundler live-reload will use a scheduler as a fallback");
enableBundlingWatch = false;
if (enableBundlingWatch.getAndSet(false)) {
LOGGER.warn(
"The sources are necessary by the Web Bundler to allow filesystem watch. Web Bundler live-reload will use a scheduler as a fallback");
}
Files.copy(webAsset.resource().path(), targetPath, StandardCopyOption.REPLACE_EXISTING);
}
}
Expand Down

0 comments on commit 1fdaf6a

Please sign in to comment.