Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of case-sensitive file key checking #165

Closed
wants to merge 7 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -208,6 +209,8 @@ private void addModuleFiles(

List<String> allFiles = FileUtils.getFileNames(moduleBasedir, "**/*", excludes, false);

Map<String, String> caseInsensitiveFiles = new HashMap<>();

for (String extension : module.getExtensions()) {
String fullExtension = "." + extension;

Expand Down Expand Up @@ -243,23 +246,22 @@ private void addModuleFiles(
// -----------------------------------------------------------------------
// Handle key without case differences
// -----------------------------------------------------------------------
for (Map.Entry<String, DocumentRenderer> entry : files.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
DocumentRenderingContext originalDocRenderingContext =
entry.getValue().getRenderingContext();
String originalKey = caseInsensitiveFiles.put(key.toLowerCase(), key);
michael-o marked this conversation as resolved.
Show resolved Hide resolved
if (originalKey != null) {
DocumentRenderingContext originalDocRenderingContext =
files.get(originalKey).getRenderingContext();

File originalDoc = new File(
originalDocRenderingContext.getBasedir(), originalDocRenderingContext.getInputName());
File originalDoc = new File(
originalDocRenderingContext.getBasedir(), originalDocRenderingContext.getInputName());

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
throw new RendererException("File '" + module.getSourceDirectory() + File.separator + doc
+ "' clashes with existing '" + originalDoc + "'.");
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
throw new RendererException("File '" + module.getSourceDirectory() + File.separator + doc
+ "' clashes with existing '" + originalDoc + "'.");
}

if (LOGGER.isWarnEnabled()) {
LOGGER.warn("File '" + module.getSourceDirectory() + File.separator + doc
+ "' could clash with existing '" + originalDoc + "'.");
}
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("File '" + module.getSourceDirectory() + File.separator + doc
+ "' could clash with existing '" + originalDoc + "'.");
}
}

Expand Down