Issue #10213 Ensuring proper usage of StartLog logging (to prevent accidental exceptions) (#10214)

This commit is contained in:
Joakim Erdfelt 2023-08-17 07:37:40 -05:00 committed by GitHub
parent fd1413db58
commit 6702634494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 31 additions and 36 deletions

View File

@ -207,7 +207,7 @@ public class BaseBuilder
List<String> startLines = new ArrayList<>();
for (Path path : paths)
{
StartLog.info("copy " + baseHome.toShortForm(path) + " into " + baseHome.toShortForm(startini));
StartLog.info("copy %s into %s", baseHome.toShortForm(path), baseHome.toShortForm(startini));
startLines.add("");
startLines.add("# Config from " + baseHome.toShortForm(path));
startLines.addAll(Files.readAllLines(path));
@ -250,7 +250,7 @@ public class BaseBuilder
if (FS.ensureDirectoryExists(startd))
{
StartLog.info("mkdir " + baseHome.toShortForm(startd));
StartLog.info("mkdir %s", baseHome.toShortForm(startd));
modified.set(true);
}

View File

@ -23,12 +23,9 @@ import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jetty.util.FileID;
@ -130,7 +127,7 @@ public class FS
if (!Files.isDirectory(path))
{
// not a directory (as expected)
StartLog.warn("Not a directory: " + path);
StartLog.warn("Not a directory: %s", path);
return false;
}

View File

@ -14,14 +14,10 @@
package org.eclipse.jetty.start;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URLConnection;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.HashSet;
import java.util.Set;
@ -167,7 +163,7 @@ public abstract class FileInitializer
{
if (FS.ensureDirectoryExists(to))
{
StartLog.info("mkdir " + _basehome.toShortForm(to));
StartLog.info("mkdir %s", _basehome.toShortForm(to));
modified = true;
}

View File

@ -186,8 +186,8 @@ public class Main
StartLog.error("Do not start with ${jetty.base} == ${jetty.home}!");
else
StartLog.error("No enabled jetty modules found!");
StartLog.info("${jetty.home} = " + getBaseHome().getHomePath());
StartLog.info("${jetty.base} = " + getBaseHome().getBasePath());
StartLog.info("${jetty.home} = %s", getBaseHome().getHomePath());
StartLog.info("${jetty.base} = %s", getBaseHome().getBasePath());
StartLog.error("Please create and/or configure a ${jetty.base} directory.");
usageExit(ERR_INVOKE_MAIN);
return;
@ -201,7 +201,7 @@ public class Main
}
catch (ClassNotFoundException e)
{
StartLog.error("Unable to find: " + mainclass);
StartLog.error("Unable to find: %s", mainclass);
StartLog.debug(e);
usageExit(ERR_INVOKE_MAIN);
return;
@ -489,7 +489,7 @@ public class Main
final Process process = pbuilder.start();
Runtime.getRuntime().addShutdownHook(new Thread(() ->
{
StartLog.debug("Destroying " + process);
StartLog.debug("Destroying %s", process);
process.destroy();
}));
@ -685,7 +685,7 @@ public class Main
}
else
{
StartLog.warn("Unable to find resource: " + resourceName);
StartLog.warn("Unable to find resource: %s", resourceName);
}
}
catch (IOException e)

View File

@ -42,7 +42,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
private void addHit(Path path)
{
String relPath = basePath.relativize(path).toString();
StartLog.debug("Found [" + relPath + "] " + path);
StartLog.debug("Found [%s] %s", relPath, path);
hits.put(relPath, path);
}
@ -76,7 +76,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
{
if (dirMatcher.matches(dir))
{
StartLog.trace("Following dir: " + dir);
StartLog.trace("Following dir: %s", dir);
if (includeDirsInResults && fileMatcher.matches(dir))
{
addHit(dir);
@ -85,7 +85,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
}
else
{
StartLog.trace("Skipping dir: " + dir);
StartLog.trace("Skipping dir: %s", dir);
return FileVisitResult.SKIP_SUBTREE;
}
}
@ -131,7 +131,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
}
else
{
StartLog.trace("Ignoring file: " + file);
StartLog.trace("Ignoring file: %s", file);
}
return FileVisitResult.CONTINUE;
}
@ -143,7 +143,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
{
if (!NOTIFIED_PATHS.contains(file))
{
StartLog.warn("skipping detected filesystem loop: " + file);
StartLog.warn("skipping detected filesystem loop: %s", file);
NOTIFIED_PATHS.add(file);
}
return FileVisitResult.SKIP_SUBTREE;

View File

@ -84,7 +84,7 @@ public class PathMatchers
// use FileSystem default pattern behavior
if (pattern.startsWith("glob:") || pattern.startsWith("regex:"))
{
StartLog.debug("Using Standard " + fs.getClass().getName() + " pattern: " + pattern);
StartLog.debug("Using Standard %s pattern: %s", fs.getClass().getName(), pattern);
return fs.getPathMatcher(pattern);
}
@ -93,14 +93,14 @@ public class PathMatchers
if (isAbsolute(pattern))
{
String pat = "glob:" + pattern;
StartLog.debug("Using absolute path pattern: " + pat);
StartLog.debug("Using absolute path pattern: %s", pat);
return fs.getPathMatcher(pat);
}
// Doesn't start with filesystem root, then assume the pattern
// is a relative file path pattern.
String pat = "glob:**/" + pattern;
StartLog.debug("Using relative path pattern: " + pat);
StartLog.debug("Using relative path pattern: %s", pat);
return fs.getPathMatcher(pat);
}

View File

@ -428,9 +428,9 @@ public class StartArgs
for (String rawlibref : module.getLibs())
{
StartLog.debug("rawlibref = " + rawlibref);
StartLog.debug("rawlibref = %s", rawlibref);
String libref = environment.getProperties().expand(rawlibref);
StartLog.debug("expanded = " + libref);
StartLog.debug("expanded = %s", libref);
for (Path libpath : baseHome.getPaths(libref))
{
@ -555,6 +555,7 @@ public class StartArgs
if (parts.contains("path"))
{
Classpath classpath = jettyEnvironment.getClasspath();
StartLog.debug("classpath=%s - isJPMS=%b", classpath, isJPMS());
if (isJPMS())
{
Map<Boolean, List<Path>> dirsAndFiles = StreamSupport.stream(classpath.spliterator(), false)
@ -605,6 +606,7 @@ public class StartArgs
}
generateJpmsArgs(cmd);
StartLog.debug("JPMS resulting cmd=%s", cmd.toCommandLine());
}
else if (!classpath.isEmpty())
{
@ -1255,7 +1257,7 @@ public class StartArgs
if (arg.startsWith("--add-to-start=") || arg.startsWith("--add-to-startd="))
{
String value = Props.getValue(arg);
StartLog.warn("Option " + arg.split("=")[0] + " is deprecated! Instead use: --add-modules=%s", value);
StartLog.warn("Option %s is deprecated! Instead use: --add-modules=%s", arg.split("=")[0], value);
}
startModules.addAll(Props.getValues(arg));
run = false;

View File

@ -231,9 +231,9 @@ public class StartEnvironment
StartLog.debug("Expanding Libs");
for (String rawlibref : _libRefs)
{
StartLog.debug("rawlibref = " + rawlibref);
StartLog.debug("rawlibref = %s", rawlibref);
String libref = getProperties().expand(rawlibref);
StartLog.debug("expanded = " + libref);
StartLog.debug("expanded = %s", libref);
// perform path escaping (needed by windows)
libref = libref.replaceAll("\\\\([^\\\\])", "\\\\\\\\$1");

View File

@ -42,7 +42,7 @@ public class StartDirBuilder implements BaseBuilder.Config
this.baseHome = baseBuilder.getBaseHome();
this.startDir = baseHome.getBasePath("start.d");
if (FS.ensureDirectoryExists(startDir))
StartLog.info("mkdir " + baseHome.toShortForm(startDir));
StartLog.info("mkdir %s", baseHome.toShortForm(startDir));
}
@Override

View File

@ -64,7 +64,7 @@ public class BaseHomeFileInitializer extends FileInitializer
else if (FS.ensureDirectoryExists(destination))
{
modified = true;
StartLog.info("mkdir " + _basehome.toShortForm(destination));
StartLog.info("mkdir %s", _basehome.toShortForm(destination));
}
copyDirectory(source, destination);
@ -74,7 +74,7 @@ public class BaseHomeFileInitializer extends FileInitializer
if (FS.ensureDirectoryExists(destination.getParent()))
{
modified = true;
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
StartLog.info("mkdir %s", _basehome.toShortForm(destination.getParent()));
}
if (!FS.exists(destination))

View File

@ -61,7 +61,7 @@ public abstract class DownloadFileInitializer extends FileInitializer
}
if (FS.ensureDirectoryExists(destination.getParent()))
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
StartLog.info("mkdir %s", _basehome.toShortForm(destination.getParent()));
StartLog.info("download %s to %s", uri, _basehome.toShortForm(destination));

View File

@ -73,7 +73,7 @@ public class LocalFileInitializer extends FileInitializer
// Create directory
boolean mkdir = FS.ensureDirectoryExists(destination);
if (mkdir)
StartLog.info("mkdir " + _basehome.toShortForm(destination));
StartLog.info("mkdir %s", _basehome.toShortForm(destination));
return mkdir;
}

View File

@ -165,7 +165,7 @@ public class MavenLocalRepoFileInitializer extends DownloadFileInitializer
if (!FS.canReadFile(localFile))
{
if (FS.ensureDirectoryExists(localFile.getParent()))
StartLog.info("mkdir " + _basehome.toShortForm(localFile.getParent()));
StartLog.info("mkdir %s", _basehome.toShortForm(localFile.getParent()));
download(coords, localFile);
if (!FS.canReadFile(localFile))
{
@ -209,7 +209,7 @@ public class MavenLocalRepoFileInitializer extends DownloadFileInitializer
if (localRepoFile != null)
{
if (FS.ensureDirectoryExists(destination.getParent()))
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
StartLog.info("mkdir %s", _basehome.toShortForm(destination.getParent()));
StartLog.info("copy %s to %s", localRepoFile, _basehome.toShortForm(destination));
Files.copy(localRepoFile, destination);
return true;