Remove java.io.File usage from jetty-start (#8355)

* This corrects our URL/URI/URLClassLoader behaviors
  to always produce to-spec URIs for `file://` references.
This commit is contained in:
Joakim Erdfelt 2022-07-29 06:05:03 -05:00 committed by GitHub
parent e78250bc3c
commit b202374d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 126 additions and 184 deletions

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
@ -69,15 +68,6 @@ public class BaseHome
return dir.resolve(FS.separators(subpath));
}
public SearchDir setDir(File path)
{
if (path != null)
{
return setDir(path.toPath());
}
return this;
}
public SearchDir setDir(Path path)
{
if (path != null)
@ -99,7 +89,7 @@ public class BaseHome
public String toShortForm(Path path)
{
Path relative = dir.relativize(path);
return String.format("${%s}%c%s", name, File.separatorChar, relative.toString());
return String.format("${%s}%s%s", name, FS.separator(), relative);
}
}
@ -398,17 +388,6 @@ public class BaseHome
return homeDir.compareTo(baseDir) != 0;
}
/**
* Convenience method for <code>toShortForm(file.toPath())</code>
*
* @param path the path to shorten
* @return the short form of the path as a String
*/
public String toShortForm(final File path)
{
return toShortForm(path.toPath());
}
/**
* Replace/Shorten arbitrary path with property strings <code>"${jetty.home}"</code> or <code>"${jetty.base}"</code> where appropriate.
*
@ -430,7 +409,7 @@ public class BaseHome
if (dirsource.isPropertyBased())
{
Path relative = dir.relativize(apath);
return String.format("%s%c%s", dirsource.getId(), File.separatorChar, relative.toString());
return String.format("%s%s%s", dirsource.getId(), FS.separator(), relative.toString());
}
else
{

View File

@ -13,21 +13,24 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
/**
* Class to handle CLASSPATH construction
*/
public class Classpath implements Iterable<File>
public class Classpath implements Iterable<Path>
{
private static class Loader extends URLClassLoader
{
@ -48,7 +51,7 @@ public class Classpath implements Iterable<File>
}
}
private final List<File> elements = new ArrayList<File>();
private final List<Path> elements = new ArrayList<>();
public Classpath()
{
@ -64,7 +67,7 @@ public class Classpath implements Iterable<File>
boolean added = false;
if (s != null)
{
StringTokenizer t = new StringTokenizer(s, File.pathSeparator);
StringTokenizer t = new StringTokenizer(s, FS.pathSeparator());
while (t.hasMoreTokens())
{
added |= addComponent(t.nextToken());
@ -73,10 +76,10 @@ public class Classpath implements Iterable<File>
return added;
}
public boolean addComponent(File file)
public boolean addComponent(Path file)
{
StartLog.debug("Adding classpath component: %s", file);
if ((file == null) || (!file.exists()))
if ((file == null) || (!Files.exists(file)))
{
// not a valid component
return false;
@ -84,7 +87,7 @@ public class Classpath implements Iterable<File>
try
{
File key = file.getCanonicalFile();
Path key = file.toRealPath();
if (!elements.contains(key))
{
elements.add(key);
@ -107,7 +110,7 @@ public class Classpath implements Iterable<File>
return false;
}
return addComponent(new File(component));
return addComponent(Paths.get(component));
}
public int count()
@ -118,21 +121,22 @@ public class Classpath implements Iterable<File>
public void dump(PrintStream out)
{
int i = 0;
for (File element : elements)
for (Path element : elements)
{
out.printf("%2d: %s%n", i++, element.getAbsolutePath());
out.printf("%2d: %s%n", i++, element);
}
}
public ClassLoader getClassLoader()
{
int cnt = elements.size();
URL[] urls = new URL[cnt];
for (int i = 0; i < cnt; i++)
{
try
{
urls[i] = elements.get(i).toURI().toURL();
urls[i] = elements.get(i).toUri().toURL();
StartLog.debug("URLClassLoader.url[%d] = %s", i, urls[i]);
}
catch (MalformedURLException e)
@ -154,7 +158,7 @@ public class Classpath implements Iterable<File>
return new Loader(urls, parent);
}
public List<File> getElements()
public List<Path> getElements()
{
return elements;
}
@ -165,7 +169,7 @@ public class Classpath implements Iterable<File>
}
@Override
public Iterator<File> iterator()
public Iterator<Path> iterator()
{
return elements.iterator();
}
@ -177,7 +181,7 @@ public class Classpath implements Iterable<File>
*/
public void overlay(Classpath other)
{
for (File otherElement : other.elements)
for (Path otherElement : other.elements)
{
if (this.elements.contains(otherElement))
{
@ -191,17 +195,8 @@ public class Classpath implements Iterable<File>
@Override
public String toString()
{
StringBuffer cp = new StringBuffer(1024);
boolean needDelim = false;
for (File element : elements)
{
if (needDelim)
{
cp.append(File.pathSeparatorChar);
}
cp.append(element.getAbsolutePath());
needDelim = true;
}
return cp.toString();
return elements.stream()
.map(Path::toString)
.collect(Collectors.joining(FS.pathSeparator()));
}
}

View File

@ -13,42 +13,27 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class CommandLineBuilder
{
public static File findExecutable(File root, String path)
{
String npath = path.replace('/', File.separatorChar);
File exe = new File(root, npath);
if (!exe.exists())
{
return null;
}
return exe;
}
public static String findJavaBin()
{
File javaHome = new File(System.getProperty("java.home"));
if (!javaHome.exists())
{
Path javaHome = Paths.get(System.getProperty("java.home"));
if (!Files.exists(javaHome))
return null;
}
File javabin = findExecutable(javaHome, "bin/java");
if (javabin != null)
{
return javabin.getAbsolutePath();
}
Path javabin = javaHome.resolve("bin/java");
if (Files.exists(javabin))
return javabin.toAbsolutePath().toString();
javabin = findExecutable(javaHome, "bin/java.exe");
if (javabin != null)
{
return javabin.getAbsolutePath();
}
javabin = javaHome.resolve("bin/java.exe");
if (Files.exists(javabin))
return javabin.toAbsolutePath().toString();
return "java";
}

View File

@ -13,8 +13,8 @@
package org.eclipse.jetty.start;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
@ -167,9 +167,9 @@ public class Environment
if (Files.isReadable(path))
{
Properties props = new Properties();
try
try (InputStream in = Files.newInputStream(path))
{
props.load(new FileInputStream(path.toFile()));
props.load(in);
for (Object key : props.keySet())
{
out.printf(" %s:%s = %s%n", p, key, props.getProperty(String.valueOf(key)));
@ -235,7 +235,7 @@ public class Environment
for (Path libpath : _baseHome.getPaths(libref))
{
getClasspath().addComponent(libpath.toFile());
getClasspath().addComponent(libpath);
}
}
}

View File

@ -28,6 +28,16 @@ import java.util.zip.ZipFile;
public class FS
{
public static String separator()
{
return FileSystems.getDefault().getSeparator();
}
public static String pathSeparator()
{
return File.pathSeparator;
}
public static boolean canReadDirectory(Path path)
{
return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path);
@ -125,9 +135,9 @@ public class FS
return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml");
}
public static String toRelativePath(File baseDir, File path)
public static String toRelativePath(Path baseDir, Path path)
{
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
return baseDir.toUri().relativize(path.toUri()).toASCIIString();
}
public static boolean isPropertyFile(String filename)

View File

@ -13,9 +13,9 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
@ -136,9 +136,9 @@ public class JarVersion
return null; // no valid impl version entries found
}
public static String getVersion(File file)
public static String getVersion(Path file)
{
try (JarFile jar = new JarFile(file))
try (JarFile jar = new JarFile(file.toFile()))
{
String version = null;

View File

@ -14,7 +14,6 @@
package org.eclipse.jetty.start;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -153,7 +152,7 @@ public class Main
out.println(" changes to the --module=name command line options will be reflected here.");
int i = 0;
for (File element : classpath.getElements())
for (Path element : classpath.getElements())
{
out.printf("%2d: %24s | %s\n", i++, getVersion(element), baseHome.toShortForm(element));
}
@ -164,16 +163,16 @@ public class Main
return baseHome;
}
private String getVersion(File element)
private String getVersion(Path element)
{
if (element.isDirectory())
if (Files.isDirectory(element))
{
return "(dir)";
}
if (element.isFile())
if (Files.isRegularFile(element))
{
String name = element.getName().toLowerCase(Locale.ENGLISH);
String name = element.toString().toLowerCase(Locale.ENGLISH);
if (name.endsWith(".jar"))
{
return JarVersion.getVersion(element);

View File

@ -13,8 +13,8 @@
package org.eclipse.jetty.start;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
@ -71,7 +71,7 @@ public class Modules implements Iterable<Module>
Path deprecatedPath = _baseHome.getPath("modules/deprecated.properties");
if (deprecatedPath != null && FS.exists(deprecatedPath))
{
try (FileInputStream inputStream = new FileInputStream(deprecatedPath.toFile()))
try (InputStream inputStream = Files.newInputStream(deprecatedPath))
{
_deprecated.load(inputStream);
}

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.nio.file.Path;
import java.text.CollationKey;
import java.text.Collator;
@ -37,19 +36,6 @@ public class NaturalSort
}
}
public static class Files implements Comparator<File>
{
private final Collator collator = Collator.getInstance();
@Override
public int compare(File o1, File o2)
{
CollationKey key1 = collator.getCollationKey(o1.getAbsolutePath());
CollationKey key2 = collator.getCollationKey(o2.getAbsolutePath());
return key1.compareTo(key2);
}
}
public static class Strings implements Comparator<String>
{
private final Collator collator = Collator.getInstance();

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystemLoopException;
import java.nio.file.FileVisitResult;
@ -57,14 +56,9 @@ public class PathFinder extends SimpleFileVisitor<Path>
return fileMatcher;
}
public List<File> getHitList()
public List<Path> getHitList()
{
List<File> ret = new ArrayList<>();
for (Path path : hits.values())
{
ret.add(path.toFile());
}
return ret;
return new ArrayList<>(hits.values());
}
public Collection<Path> getHits()

View File

@ -13,13 +13,13 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
/**
* Common PathMatcher implementations.
@ -45,7 +45,7 @@ public class PathMatchers
private static final char[] GLOB_CHARS = "*?".toCharArray();
private static final char[] SYNTAXED_GLOB_CHARS = "{}[]|:".toCharArray();
private static final Path EMPTY_PATH = new File(".").toPath();
private static final Path EMPTY_PATH = Paths.get(".");
/**
* Convert a pattern to a Path object.
@ -64,7 +64,7 @@ public class PathMatchers
{
test = test.substring("regex:".length());
}
return new File(test).toPath();
return Paths.get(test);
}
public static PathMatcher getMatcher(final String rawpattern)
@ -221,7 +221,7 @@ public class PathMatchers
/**
* Determine if part is a glob pattern.
*
* @param part the string to check
* @param c the char to check
* @param syntaxed true if overall pattern is syntaxed with <code>"glob:"</code> or <code>"regex:"</code>
* @return true if part has glob characters
*/

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
@ -424,7 +423,7 @@ public class StartArgs
for (Path libpath : baseHome.getPaths(libref))
{
environment.getClasspath().addComponent(libpath.toFile());
environment.getClasspath().addComponent(libpath);
}
}
@ -540,24 +539,26 @@ public class StartArgs
{
if (isJPMS())
{
Map<Boolean, List<File>> dirsAndFiles = StreamSupport.stream(coreEnvironment.getClasspath().spliterator(), false)
.collect(Collectors.groupingBy(File::isDirectory));
List<File> files = dirsAndFiles.get(false);
Map<Boolean, List<Path>> dirsAndFiles = StreamSupport.stream(coreEnvironment.getClasspath().spliterator(), false)
.collect(Collectors.groupingBy(Files::isDirectory));
List<Path> files = dirsAndFiles.get(false);
if (files != null && !files.isEmpty())
{
cmd.addRawArg("--module-path");
String modules = files.stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator));
.map(Path::toAbsolutePath)
.map(Path::toString)
.collect(Collectors.joining(FS.pathSeparator()));
cmd.addRawArg(modules);
}
List<File> dirs = dirsAndFiles.get(true);
List<Path> dirs = dirsAndFiles.get(true);
if (dirs != null && !dirs.isEmpty())
{
cmd.addRawArg("--class-path");
String directories = dirs.stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator));
.map(Path::toAbsolutePath)
.map(Path::toString)
.collect(Collectors.joining(FS.pathSeparator()));
cmd.addRawArg(directories);
}
@ -598,7 +599,7 @@ public class StartArgs
propPath.toFile().deleteOnExit();
}
else
propPath = new File(execProperties).toPath();
propPath = Paths.get(execProperties);
try (OutputStream out = Files.newOutputStream(propPath))
{
@ -628,7 +629,9 @@ public class StartArgs
cmd.addArg(environment.getName());
environment.getClasspath().getElements().stream()
.map(File::getAbsolutePath).forEach(s ->
.map(Path::toAbsolutePath)
.map(Path::toString)
.forEach(s ->
{
cmd.addArg("-cp");
cmd.addArg(s);
@ -640,7 +643,7 @@ public class StartArgs
cmd.addArg(property.key + "=" + property.value);
for (Path xmlFile : environment.getXmlFiles())
cmd.addArg(xmlFile.toFile().getAbsolutePath());
cmd.addArg(xmlFile.toAbsolutePath().toString());
}
}
@ -694,7 +697,7 @@ public class StartArgs
int equals = valueString.indexOf('=');
if (equals <= 0)
throw new IllegalArgumentException("Invalid [jpms] directive " + directive + " in module " + module.getName() + ": " + line);
String delimiter = valueIsFile ? File.pathSeparator : ",";
String delimiter = valueIsFile ? FS.pathSeparator() : ",";
String key = valueString.substring(0, equals).trim();
String[] values = valueString.substring(equals + 1).split(delimiter);
Set<String> result = output.computeIfAbsent(key, k -> new LinkedHashSet<>());
@ -723,7 +726,7 @@ public class StartArgs
for (Map.Entry<String, Set<String>> entry : _jmodPatch.entrySet())
{
cmd.addRawArg("--patch-module");
cmd.addRawArg(entry.getKey() + "=" + String.join(File.pathSeparator, entry.getValue()));
cmd.addRawArg(entry.getKey() + "=" + String.join(FS.pathSeparator(), entry.getValue()));
}
for (Map.Entry<String, Set<String>> entry : _jmodOpens.entrySet())
{
@ -784,7 +787,7 @@ public class StartArgs
return null;
}
Path localRepoDir = new File(localRepo).toPath();
Path localRepoDir = Paths.get(localRepo);
localRepoDir = localRepoDir.normalize().toAbsolutePath();
if (Files.exists(localRepoDir) && Files.isDirectory(localRepoDir))
{
@ -1222,7 +1225,7 @@ public class StartArgs
if (arg.startsWith("--lib="))
{
String cp = Props.getValue(arg);
StringTokenizer t = new StringTokenizer(cp, File.pathSeparator);
StringTokenizer t = new StringTokenizer(cp, FS.pathSeparator());
while (t.hasMoreTokens())
environment.addLibRef(t.nextToken());
return environment;

View File

@ -13,11 +13,11 @@
package org.eclipse.jetty.start.config;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -114,7 +114,7 @@ public class CommandLineConfigSource implements ConfigSource
// ${jetty.home} is relative to found BaseHome class
try
{
Path home = new File(new URI(m.group(1))).getParentFile().toPath();
Path home = Paths.get(new URI(m.group(1))).getParent();
setProperty(BaseHome.JETTY_HOME, home.toString(), ORIGIN_INTERNAL_FALLBACK);
return home;
}

View File

@ -15,6 +15,8 @@ package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +24,6 @@ import java.util.List;
import org.eclipse.jetty.start.config.ConfigSources;
import org.eclipse.jetty.start.config.JettyBaseConfigSource;
import org.eclipse.jetty.start.config.JettyHomeConfigSource;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.jupiter.api.Test;
@ -39,7 +40,7 @@ public class BaseHomeTest
List<String> actual = new ArrayList<>();
for (Path path : finder.getHits())
{
actual.add(hb.toShortForm(path.toFile()));
actual.add(hb.toShortForm(path));
}
if (actual.size() != expected.size())
@ -63,7 +64,7 @@ public class BaseHomeTest
List<String> actual = new ArrayList<>();
for (Path path : paths)
{
actual.add(hb.toShortForm(path.toFile()));
actual.add(hb.toShortForm(path));
}
if (actual.size() != expected.size())
@ -82,16 +83,6 @@ public class BaseHomeTest
assertThat(message + ": " + Utils.join(actual, ", "), actual, containsInAnyOrder(expected.toArray()));
}
public static void assertFileList(BaseHome hb, String message, List<String> expected, List<File> files)
{
List<String> actual = new ArrayList<>();
for (File file : files)
{
actual.add(hb.toShortForm(file));
}
assertThat(message + ": " + Utils.join(actual, ", "), actual, containsInAnyOrder(expected.toArray()));
}
@Test
public void testGetPathOnlyHome() throws IOException
{
@ -106,7 +97,7 @@ public class BaseHomeTest
String ref = hb.toShortForm(startIni);
assertThat("Reference", ref, startsWith("${jetty.home}"));
String contents = IO.readToString(startIni.toFile());
String contents = Files.readString(startIni, StandardCharsets.UTF_8);
assertThat("Contents", contents, containsString("Home Ini"));
}
@ -203,7 +194,7 @@ public class BaseHomeTest
String ref = hb.toShortForm(startIni);
assertThat("Reference", ref, startsWith("${jetty.base}"));
String contents = IO.readToString(startIni.toFile());
String contents = Files.readString(startIni, StandardCharsets.UTF_8);
assertThat("Contents", contents, containsString("Base Ini"));
}
}

View File

@ -13,7 +13,7 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.nio.file.Path;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.jupiter.api.Test;
@ -25,7 +25,7 @@ public class JarVersionTest
{
private void assertJarVersion(String jarname, String expectedVersion)
{
File jarfile = MavenTestingUtils.getTestResourceFile(jarname);
Path jarfile = MavenTestingUtils.getTestResourcePathFile(jarname);
assertThat("Jar: " + jarname, JarVersion.getVersion(jarfile), containsString(expectedVersion));
}

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -46,16 +47,16 @@ public class ModulesTest
public void testLoadAllModules() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("dist-home");
File baseDir = testdir.getEmptyPathDir().toFile();
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
@ -142,16 +143,16 @@ public class ModulesTest
public void testResolveServerHttp() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("dist-home");
File baseDir = testdir.getEmptyPathDir().toFile();
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
@ -205,16 +206,16 @@ public class ModulesTest
public void testResolveNotRequiredModuleNotFound() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("non-required-deps");
File baseDir = testdir.getEmptyPathDir().toFile();
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=cannot-find-me"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
@ -254,16 +255,16 @@ public class ModulesTest
public void testResolveNotRequiredModuleFound() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("non-required-deps");
File baseDir = testdir.getEmptyPathDir().toFile();
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=dive"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
@ -305,16 +306,16 @@ public class ModulesTest
public void testResolveNotRequiredModuleFoundDynamic() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("non-required-deps");
File baseDir = testdir.getEmptyPathDir().toFile();
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=dynamic"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);

View File

@ -14,7 +14,6 @@
package org.eclipse.jetty.start;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
@ -29,8 +28,8 @@ public class TestEnv
public static void copyTestDir(String testResourceDir, Path destDir) throws IOException
{
FS.ensureDirExists(destDir);
File srcDir = MavenTestingUtils.getTestResourceDir(testResourceDir);
IO.copyDir(srcDir, destDir.toFile());
Path srcDir = MavenTestingUtils.getTestResourcePathDir(testResourceDir);
IO.copyDir(srcDir.toFile(), destDir.toFile());
}
public static void makeFile(Path dir, String relFilePath, String... contents) throws IOException

View File

@ -111,7 +111,7 @@ public class ConfigSourcesTest
// Create common
Path common = testdir.getPathFile("common");
FS.ensureEmpty(common.toFile());
FS.ensureEmpty(common);
common = common.toRealPath();
// Create base

View File

@ -196,7 +196,7 @@ public class MavenLocalRepoFileInitializerTest
Files.deleteIfExists(destination);
repo.download(coords.toCentralURI(), destination);
assertThat(Files.exists(destination), is(true));
assertThat(destination.toFile().length(), is(986193L));
assertThat(Files.size(destination), is(986193L));
}
@Test
@ -224,7 +224,7 @@ public class MavenLocalRepoFileInitializerTest
Path destination = baseHome.getBasePath().resolve("jetty-rewrite-11.0.0-SNAPSHOT.jar");
repo.download(coords, destination);
assertThat(Files.exists(destination), is(true));
assertThat("Snapshot File size", destination.toFile().length(), greaterThan(10_000L));
assertThat("Snapshot File size", Files.size(destination), greaterThan(10_000L));
}
@Test

View File

@ -116,7 +116,7 @@ public class EnvironmentsTest extends AbstractUseCase
Environment environment = results.getEnvironment(e);
assertThat(environment, notNullValue());
assertThat(environment.getName(), is(e));
assertThat(environment.getClasspath().getElements(), contains(baseDir.resolve("lib/%s.jar".formatted(e)).toFile()));
assertThat(environment.getClasspath().getElements(), contains(baseDir.resolve("lib/%s.jar".formatted(e))));
assertThat(environment.getXmlFiles(), contains(baseDir.resolve("etc/%s.xml".formatted(e))));
assertThat(environment.getProperties().getProp("feature.option").value, is(e));
}

View File

@ -124,7 +124,7 @@ public class RebuildTestResources
{
System.out.println("Copying libs (lib dir) ...");
Path libsDir = destDir.resolve("lib");
FS.ensureDirExists(libsDir.toFile());
FS.ensureDirExists(libsDir);
PathMatcher matcher = getPathMatcher("glob:**.jar");
Renamer renamer = new RegexRenamer("-9\\.[0-9.]*(v[0-9-]*)?(-SNAPSHOT)?(RC[0-9])?(M[0-9])?", "-" + JETTY_VERSION);
@ -136,7 +136,7 @@ public class RebuildTestResources
{
System.out.println("Copying modules ...");
Path modulesDir = destDir.resolve("modules");
FS.ensureDirExists(modulesDir.toFile());
FS.ensureDirExists(modulesDir);
PathMatcher matcher = getPathMatcher("glob:**.mod");
Renamer renamer = new NoRenamer();
@ -148,7 +148,7 @@ public class RebuildTestResources
{
System.out.println("Copying xmls (etc dir) ...");
Path xmlDir = destDir.resolve("etc");
FS.ensureDirExists(xmlDir.toFile());
FS.ensureDirExists(xmlDir);
PathMatcher matcher = getPathMatcher("glob:**.xml");
Renamer renamer = new NoRenamer();