Replace "folder" with "directory"

Consistently use the term "directory" instead of "folder"

Closes gh-21218
This commit is contained in:
Phillip Webb
2020-04-28 18:27:41 -07:00
parent ec871d6752
commit ad1248e4ec
98 changed files with 853 additions and 835 deletions

View File

@@ -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.
@@ -66,23 +66,23 @@ class ResourceMatcher {
matchedResources.add(new MatchedResource(root));
}
else {
matchedResources.addAll(findInFolder(root));
matchedResources.addAll(findInDirectory(root));
}
}
return matchedResources;
}
private List<MatchedResource> findInFolder(File folder) throws IOException {
private List<MatchedResource> findInDirectory(File directory) throws IOException {
List<MatchedResource> matchedResources = new ArrayList<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
new FolderResourceLoader(folder));
new DirectoryResourceLoader(directory));
for (String include : this.includes) {
for (Resource candidate : resolver.getResources(include)) {
File file = candidate.getFile();
if (file.isFile()) {
MatchedResource matchedResource = new MatchedResource(folder, file);
MatchedResource matchedResource = new MatchedResource(directory, file);
if (!isExcluded(matchedResource)) {
matchedResources.add(matchedResource);
}
@@ -130,31 +130,31 @@ class ResourceMatcher {
}
/**
* {@link ResourceLoader} to get load resource from a folder.
* {@link ResourceLoader} to get load resource from a directory.
*/
private static class FolderResourceLoader extends DefaultResourceLoader {
private static class DirectoryResourceLoader extends DefaultResourceLoader {
private final File rootFolder;
private final File rootDirectory;
FolderResourceLoader(File root) throws MalformedURLException {
super(new FolderClassLoader(root));
this.rootFolder = root;
DirectoryResourceLoader(File root) throws MalformedURLException {
super(new DirectoryClassLoader(root));
this.rootDirectory = root;
}
@Override
protected Resource getResourceByPath(String path) {
return new FileSystemResource(new File(this.rootFolder, path));
return new FileSystemResource(new File(this.rootDirectory, path));
}
}
/**
* {@link ClassLoader} backed by a folder.
* {@link ClassLoader} backed by a directory.
*/
private static class FolderClassLoader extends URLClassLoader {
private static class DirectoryClassLoader extends URLClassLoader {
FolderClassLoader(File rootFolder) throws MalformedURLException {
super(new URL[] { rootFolder.toURI().toURL() });
DirectoryClassLoader(File rootDirectory) throws MalformedURLException {
super(new URL[] { rootDirectory.toURI().toURL() });
}
@Override
@@ -186,9 +186,10 @@ class ResourceMatcher {
this.root = this.name.endsWith(".jar");
}
private MatchedResource(File rootFolder, File file) {
this.name = StringUtils
.cleanPath(file.getAbsolutePath().substring(rootFolder.getAbsolutePath().length() + 1));
private MatchedResource(File rootDirectory, File file) {
String filePath = file.getAbsolutePath();
String rootDirectoryPath = rootDirectory.getAbsolutePath();
this.name = StringUtils.cleanPath(filePath.substring(rootDirectoryPath.length() + 1));
this.file = file;
this.root = false;
}

View File

@@ -90,23 +90,24 @@ class ProjectGenerator {
}
private void extractProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException {
File outputFolder = (output != null) ? new File(output) : new File(System.getProperty("user.dir"));
if (!outputFolder.exists()) {
outputFolder.mkdirs();
File outputDirectory = (output != null) ? new File(output) : new File(System.getProperty("user.dir"));
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(entity.getContent()))) {
extractFromStream(zipStream, overwrite, outputFolder);
fixExecutableFlag(outputFolder, "mvnw");
fixExecutableFlag(outputFolder, "gradlew");
Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'");
extractFromStream(zipStream, overwrite, outputDirectory);
fixExecutableFlag(outputDirectory, "mvnw");
fixExecutableFlag(outputDirectory, "gradlew");
Log.info("Project extracted to '" + outputDirectory.getAbsolutePath() + "'");
}
}
private void extractFromStream(ZipInputStream zipStream, boolean overwrite, File outputFolder) throws IOException {
private void extractFromStream(ZipInputStream zipStream, boolean overwrite, File outputDirectory)
throws IOException {
ZipEntry entry = zipStream.getNextEntry();
String canonicalOutputPath = outputFolder.getCanonicalPath() + File.separator;
String canonicalOutputPath = outputDirectory.getCanonicalPath() + File.separator;
while (entry != null) {
File file = new File(outputFolder, entry.getName());
File file = new File(outputDirectory, entry.getName());
String canonicalEntryPath = file.getCanonicalPath();
if (!canonicalEntryPath.startsWith(canonicalOutputPath)) {
throw new ReportableException("Entry '" + entry.getName() + "' would be written to '"