Skip to content

Commit

Permalink
Small Windows fixes for web dev and welcome page
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Jun 19, 2024
1 parent a6f5d5f commit 03ad21e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,32 @@ private RuntimeUpdatesProcessor setWatchedFilePathsInternal(Map<String, Boolean>
// Then process glob patterns
for (Entry<String, Boolean> e : watchedFilePaths.entrySet()) {
String watchedFilePath = e.getKey();
Path path = Paths.get(watchedFilePath);
if (!path.isAbsolute() && !watchedRootPaths.contains(e.getKey()) && maybeGlobPattern(watchedFilePath)) {
Path resolvedPath = root.resolve(watchedFilePath);
for (WatchedPath extra : expandGlobPattern(root, resolvedPath, watchedFilePath, e.getValue())) {
timestamps.watchedPaths.put(extra.filePath, extra);
Path path = Paths.get(sanitizedPattern(watchedFilePath));
if (!path.isAbsolute() && !watchedRootPaths.contains(e.getKey())
&& maybeGlobPattern(watchedFilePath)) {
try {
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + watchedFilePath);
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path relativePath = root.relativize(file);
if (matcher.matches(relativePath)) {
log.debugf("Glob pattern [%s] matched %s from %s", watchedFilePath, relativePath,
root);
WatchedPath extra = new WatchedPath(file, relativePath, e.getValue(),
attrs.lastModifiedTime().toMillis());
timestamps.watchedPaths.put(extra.filePath, extra);
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
Expand All @@ -1219,8 +1240,9 @@ private RuntimeUpdatesProcessor setWatchedFilePathsInternal(Map<String, Boolean>
// Finally process watched absolute paths
for (Entry<String, Boolean> e : watchedFilePaths.entrySet()) {
String watchedFilePath = e.getKey();
Path path = Paths.get(watchedFilePath);
Path path = Paths.get(sanitizedPattern(watchedFilePath));
if (path.isAbsolute()) {
path = Paths.get(watchedFilePath);
log.debugf("Watch %s", path);
if (Files.exists(path)) {
putLastModifiedTime(path, path, e.getValue(), timestamps);
Expand All @@ -1235,6 +1257,10 @@ private RuntimeUpdatesProcessor setWatchedFilePathsInternal(Map<String, Boolean>
return this;
}

private String sanitizedPattern(String pattern) {
return pattern.replaceAll("[*?]", "");
}

private boolean maybeGlobPattern(String path) {
return path.contains("*") || path.contains("?");
}
Expand Down Expand Up @@ -1282,32 +1308,6 @@ public void close() throws IOException {
}
}

private List<WatchedPath> expandGlobPattern(Path root, Path path, String pattern, boolean restart) {
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + path.toString());
List<WatchedPath> files = new ArrayList<>();
try {
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (pathMatcher.matches(file)) {
Path relativePath = root.relativize(file);
log.debugf("Glob pattern [%s] matched %s from %s", pattern, relativePath, root);
files.add(new WatchedPath(file, relativePath, restart, attrs.lastModifiedTime().toMillis()));
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return files;
}

public boolean toggleInstrumentation() {
instrumentationEnabled = !instrumentationEnabled();
if (instrumentationEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ private String getConfigFile(WorkspaceModule workspaceModule) {
Path resourceDirs = resourcesDirs.iterator().next().getDir();
Path propertiesFile = resourceDirs.resolve("application.properties");
if (Files.exists(propertiesFile)) {
return propertiesFile.toString().substring((int) root.length() + 1);
return propertiesFile.toString().replace("\\", "/").substring((int) root.length() + 1);
}
Path propertiesYaml = resourceDirs.resolve("application.yaml");
if (Files.exists(propertiesYaml)) {
return propertiesYaml.toString().substring((int) root.length() + 1);
return propertiesYaml.toString().replace("\\", "/").substring((int) root.length() + 1);
}
}
}
Expand All @@ -91,7 +91,7 @@ private String getSourceDir(WorkspaceModule workspaceModule) {
String root = moduleDir.toPath().toString();
Collection<SourceDir> sourceDirs = workspaceModule.getMainSources().getSourceDirs();
if (sourceDirs != null && !sourceDirs.isEmpty()) {
String sourceDir = sourceDirs.iterator().next().getDir().toString();
String sourceDir = sourceDirs.iterator().next().getDir().toString().replace("\\", "/");
return sourceDir.substring((int) root.length() + 1);
}
}
Expand All @@ -106,7 +106,7 @@ private String getResourcesDir(WorkspaceModule workspaceModule) {
String root = moduleDir.toPath().toString();
Collection<SourceDir> resourcesDirs = workspaceModule.getMainSources().getResourceDirs();
if (resourcesDirs != null && !resourcesDirs.isEmpty()) {
String resourceDirs = resourcesDirs.iterator().next().getDir().toString();
String resourceDirs = resourcesDirs.iterator().next().getDir().toString().replace("\\", "/");
return resourceDirs.substring((int) root.length() + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void findRelevantFiles(BuildProducer<FeatureBuildItem> feature,
.resolve(config.webRoot);

if (Files.exists(web)) {
hotDeploymentWatchedProducer.produce(new HotDeploymentWatchedFileBuildItem(config.webRoot + SLASH + STAR));
hotDeploymentWatchedProducer.produce(new HotDeploymentWatchedFileBuildItem(config.webRoot + SLASH + STAR + STAR));
// Find all css and js (under /app)
Path app = web
.resolve(config.appRoot);
Expand All @@ -65,7 +65,8 @@ public void findRelevantFiles(BuildProducer<FeatureBuildItem> feature,

if (Files.exists(app)) {
hotDeploymentWatchedProducer
.produce(new HotDeploymentWatchedFileBuildItem(config.webRoot + SLASH + config.appRoot + SLASH + STAR));
.produce(new HotDeploymentWatchedFileBuildItem(
config.webRoot + SLASH + config.appRoot + SLASH + STAR + STAR));
try (Stream<Path> appstream = Files.walk(app)) {
appstream.forEach(path -> {
if (Files.isRegularFile(path) && path.toString().endsWith(DOT_CSS)) {
Expand Down Expand Up @@ -144,15 +145,16 @@ private static String processLine(String line, List<Path> cssFiles, List<Path> j
try (StringWriter sw = new StringWriter()) {
if (!cssFiles.isEmpty()) {
for (Path css : cssFiles) {
sw.write(TAB2 + "<link href='" + css.toString() + "' rel='stylesheet'>" + NL);
sw.write(TAB2 + "<link href='" + css.toString().replace("\\", "/") + "' rel='stylesheet'>"
+ System.lineSeparator());
}
}
sw.write(TAB2 + IMPORTMAP_REPLACEMENT);
if (!jsFiles.isEmpty()) {
sw.write(NL);
sw.write(TAB2 + "<script type='module'>" + NL);
sw.write(System.lineSeparator());
sw.write(TAB2 + "<script type='module'>" + System.lineSeparator());
for (Path js : jsFiles) {
sw.write(TAB2 + TAB + "import '" + js.toString() + "';" + NL);
sw.write(TAB2 + TAB + "import '" + js.toString().replace("\\", "/") + "';" + System.lineSeparator());
}
sw.write(TAB2 + "</script>");
}
Expand Down Expand Up @@ -321,6 +323,4 @@ static class LibInfo {
private static final String DOT_HTML = ".html";
private static final String DOT_CSS = ".css";
private static final String DOT_JS = ".js";

private static final String NL = "\n";
}

0 comments on commit 03ad21e

Please sign in to comment.