Replace "folder" with "directory"
Consistently use the term "directory" instead of "folder" Closes gh-21218
This commit is contained in:
@@ -239,7 +239,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
|
||||
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler)
|
||||
throws IOException {
|
||||
String name = entry.getName();
|
||||
writeParentFolderEntries(name);
|
||||
writeParentDirectoryEntries(name);
|
||||
if (this.writtenEntries.add(name)) {
|
||||
entry.setUnixMode(name.endsWith("/") ? UNIX_DIR_MODE : UNIX_FILE_MODE);
|
||||
entry.getGeneralPurposeBit().useUTF8ForNames(true);
|
||||
@@ -254,7 +254,7 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
|
||||
|
||||
protected abstract void writeToArchive(ZipEntry entry, EntryWriter entryWriter) throws IOException;
|
||||
|
||||
private void writeParentFolderEntries(String name) throws IOException {
|
||||
private void writeParentDirectoryEntries(String name) throws IOException {
|
||||
String parent = name.endsWith("/") ? name.substring(0, name.length() - 1) : name;
|
||||
while (parent.lastIndexOf('/') != -1) {
|
||||
parent = parent.substring(0, parent.lastIndexOf('/'));
|
||||
|
||||
@@ -36,9 +36,10 @@ import org.springframework.util.MultiValueMap;
|
||||
* text files that should be read from top to bottom. Each file defines the layers and
|
||||
* their content. Layer names are written as quoted strings prefixed by a dash space
|
||||
* ({@code "- "}) and with a colon ({@code ":"}) suffix. Layer content is either a file or
|
||||
* folder name written as a quoted string prefixed by space space dash space
|
||||
* ({@code " - "}). A folder name ends with {@code /}, a file name does not. When a
|
||||
* folder name is used it means that all files inside that folder are in the same layer.
|
||||
* directory name written as a quoted string prefixed by space space dash space
|
||||
* ({@code " - "}). A directory name ends with {@code /}, a file name does not. When a
|
||||
* directory name is used it means that all files inside that directory are in the same
|
||||
* layer.
|
||||
* <p>
|
||||
* Index files are designed to be compatible with YAML and may be read into a list of
|
||||
* `Map<String, List<String>>` instances.
|
||||
@@ -79,8 +80,8 @@ public class LayersIndex {
|
||||
String[] segments = name.split("/");
|
||||
Node node = this.root;
|
||||
for (int i = 0; i < segments.length; i++) {
|
||||
boolean isFolder = i < (segments.length - 1);
|
||||
node = node.updateOrAddNode(segments[i], isFolder, layer);
|
||||
boolean isDirectory = i < (segments.length - 1);
|
||||
node = node.updateOrAddNode(segments[i], isDirectory, layer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +128,8 @@ public class LayersIndex {
|
||||
this.layers = new HashSet<>(Collections.singleton(layer));
|
||||
}
|
||||
|
||||
Node updateOrAddNode(String segment, boolean isFolder, Layer layer) {
|
||||
String name = segment + (isFolder ? "/" : "");
|
||||
Node updateOrAddNode(String segment, boolean isDirectory, Layer layer) {
|
||||
String name = segment + (isDirectory ? "/" : "");
|
||||
for (Node child : this.children) {
|
||||
if (name.equals(child.name)) {
|
||||
child.layers.add(layer);
|
||||
|
||||
@@ -64,71 +64,71 @@ public abstract class MainClassFinder {
|
||||
|
||||
private static final FileFilter CLASS_FILE_FILTER = MainClassFinder::isClassFile;
|
||||
|
||||
private static final FileFilter PACKAGE_FOLDER_FILTER = MainClassFinder::isPackageFolder;
|
||||
private static final FileFilter PACKAGE_DIRECTORY_FILTER = MainClassFinder::isPackageDirectory;
|
||||
|
||||
private static boolean isClassFile(File file) {
|
||||
return file.isFile() && file.getName().endsWith(DOT_CLASS);
|
||||
}
|
||||
|
||||
private static boolean isPackageFolder(File file) {
|
||||
private static boolean isPackageDirectory(File file) {
|
||||
return file.isDirectory() && !file.getName().startsWith(".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the main class from a given folder.
|
||||
* @param rootFolder the root folder to search
|
||||
* Find the main class from a given directory.
|
||||
* @param rootDirectory the root directory to search
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the folder cannot be read
|
||||
* @throws IOException if the directory cannot be read
|
||||
*/
|
||||
public static String findMainClass(File rootFolder) throws IOException {
|
||||
return doWithMainClasses(rootFolder, MainClass::getName);
|
||||
public static String findMainClass(File rootDirectory) throws IOException {
|
||||
return doWithMainClasses(rootDirectory, MainClass::getName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single main class from the given {@code rootFolder}.
|
||||
* @param rootFolder the root folder to search
|
||||
* Find a single main class from the given {@code rootDirectory}.
|
||||
* @param rootDirectory the root directory to search
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the folder cannot be read
|
||||
* @throws IOException if the directory cannot be read
|
||||
*/
|
||||
public static String findSingleMainClass(File rootFolder) throws IOException {
|
||||
return findSingleMainClass(rootFolder, null);
|
||||
public static String findSingleMainClass(File rootDirectory) throws IOException {
|
||||
return findSingleMainClass(rootDirectory, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single main class from the given {@code rootFolder}. A main class annotated
|
||||
* with an annotation with the given {@code annotationName} will be preferred over a
|
||||
* main class with no such annotation.
|
||||
* @param rootFolder the root folder to search
|
||||
* Find a single main class from the given {@code rootDirectory}. A main class
|
||||
* annotated with an annotation with the given {@code annotationName} will be
|
||||
* preferred over a main class with no such annotation.
|
||||
* @param rootDirectory the root directory to search
|
||||
* @param annotationName the name of the annotation that may be present on the main
|
||||
* class
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the folder cannot be read
|
||||
* @throws IOException if the directory cannot be read
|
||||
*/
|
||||
public static String findSingleMainClass(File rootFolder, String annotationName) throws IOException {
|
||||
public static String findSingleMainClass(File rootDirectory, String annotationName) throws IOException {
|
||||
SingleMainClassCallback callback = new SingleMainClassCallback(annotationName);
|
||||
MainClassFinder.doWithMainClasses(rootFolder, callback);
|
||||
MainClassFinder.doWithMainClasses(rootDirectory, callback);
|
||||
return callback.getMainClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the given callback operation on all main classes from the given root
|
||||
* folder.
|
||||
* directory.
|
||||
* @param <T> the result type
|
||||
* @param rootFolder the root folder
|
||||
* @param rootDirectory the root directory
|
||||
* @param callback the callback
|
||||
* @return the first callback result or {@code null}
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
static <T> T doWithMainClasses(File rootFolder, MainClassCallback<T> callback) throws IOException {
|
||||
if (!rootFolder.exists()) {
|
||||
static <T> T doWithMainClasses(File rootDirectory, MainClassCallback<T> callback) throws IOException {
|
||||
if (!rootDirectory.exists()) {
|
||||
return null; // nothing to do
|
||||
}
|
||||
if (!rootFolder.isDirectory()) {
|
||||
throw new IllegalArgumentException("Invalid root folder '" + rootFolder + "'");
|
||||
if (!rootDirectory.isDirectory()) {
|
||||
throw new IllegalArgumentException("Invalid root directory '" + rootDirectory + "'");
|
||||
}
|
||||
String prefix = rootFolder.getAbsolutePath() + "/";
|
||||
String prefix = rootDirectory.getAbsolutePath() + "/";
|
||||
Deque<File> stack = new ArrayDeque<>();
|
||||
stack.push(rootFolder);
|
||||
stack.push(rootDirectory);
|
||||
while (!stack.isEmpty()) {
|
||||
File file = stack.pop();
|
||||
if (file.isFile()) {
|
||||
@@ -144,7 +144,7 @@ public abstract class MainClassFinder {
|
||||
}
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
pushAllSorted(stack, file.listFiles(PACKAGE_FOLDER_FILTER));
|
||||
pushAllSorted(stack, file.listFiles(PACKAGE_DIRECTORY_FILTER));
|
||||
pushAllSorted(stack, file.listFiles(CLASS_FILE_FILTER));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class LayersIndexTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeToWhenAllFilesInFolderAreInSameLayerUsesFolder() {
|
||||
void writeToWhenAllFilesInDirectoryAreInSameLayerUsesDirectory() {
|
||||
LayersIndex index = new LayersIndex(LAYER_A, LAYER_B, LAYER_C);
|
||||
index.add(LAYER_A, "a1/b1/c1");
|
||||
index.add(LAYER_A, "a1/b1/c2");
|
||||
@@ -96,7 +96,7 @@ class LayersIndexTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeToWhenAllFilesInFolderAreInNotInSameLayerUsesFiles() {
|
||||
void writeToWhenAllFilesInDirectoryAreInNotInSameLayerUsesFiles() {
|
||||
LayersIndex index = new LayersIndex(LAYER_A, LAYER_B, LAYER_C);
|
||||
index.add(LAYER_A, "a1/b1/c1");
|
||||
index.add(LAYER_B, "a1/b1/c2");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findMainClassInJarSubFolder() throws Exception {
|
||||
void findMainClassInJarSubDirectory() throws Exception {
|
||||
this.testJarFile.addClass("a/b/c/D.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class);
|
||||
@@ -114,7 +114,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findMainClassInFolder() throws Exception {
|
||||
void findMainClassInDirectory() throws Exception {
|
||||
this.testJarFile.addClass("B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("A.class", ClassWithoutMainMethod.class);
|
||||
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource());
|
||||
@@ -122,7 +122,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findMainClassInSubFolder() throws Exception {
|
||||
void findMainClassInSubDirectory() throws Exception {
|
||||
this.testJarFile.addClass("a/b/c/D.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class);
|
||||
@@ -131,7 +131,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void usesBreadthFirstFolderSearch() throws Exception {
|
||||
void usesBreadthFirstDirectorySearch() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
|
||||
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource());
|
||||
@@ -139,7 +139,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findSingleFolderSearch() throws Exception {
|
||||
void findSingleDirectorySearch() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
|
||||
assertThatIllegalStateException()
|
||||
@@ -149,7 +149,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findSingleFolderSearchPrefersAnnotatedMainClass() throws Exception {
|
||||
void findSingleDirectorySearchPrefersAnnotatedMainClass() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
|
||||
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource(),
|
||||
@@ -158,7 +158,7 @@ class MainClassFinderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void doWithFolderMainMethods() throws Exception {
|
||||
void doWithDirectoryMainMethods() throws Exception {
|
||||
this.testJarFile.addClass("a/b/c/D.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,15 +40,15 @@ public class TestJarFile {
|
||||
|
||||
private final byte[] buffer = new byte[4096];
|
||||
|
||||
private final File temporaryFolder;
|
||||
private final File temporaryDirectory;
|
||||
|
||||
private final File jarSource;
|
||||
|
||||
private final List<ZipEntrySource> entries = new ArrayList<>();
|
||||
|
||||
public TestJarFile(File temporaryFolder) throws IOException {
|
||||
this.temporaryFolder = temporaryFolder;
|
||||
this.jarSource = new File(temporaryFolder, "jar-source");
|
||||
public TestJarFile(File temporaryDirectory) throws IOException {
|
||||
this.temporaryDirectory = temporaryDirectory;
|
||||
this.jarSource = new File(temporaryDirectory, "jar-source");
|
||||
}
|
||||
|
||||
public void addClass(String filename, Class<?> classToCopy) throws IOException {
|
||||
@@ -120,7 +120,7 @@ public class TestJarFile {
|
||||
}
|
||||
|
||||
public File getFile(String extension) throws IOException {
|
||||
File file = new File(this.temporaryFolder, UUID.randomUUID() + "." + extension);
|
||||
File file = new File(this.temporaryDirectory, UUID.randomUUID() + "." + extension);
|
||||
ZipUtil.pack(this.entries.toArray(new ZipEntrySource[0]), file);
|
||||
return file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user