[#8363] Slow check for similar generated files that differ by case
This commit is contained in:
parent
f81ddaca57
commit
e57e49a746
84
jOOQ-codegen/src/main/java/org/jooq/codegen/Files.java
Normal file
84
jOOQ-codegen/src/main/java/org/jooq/codegen/Files.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.codegen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A cache for directories and their contents.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public final class Files {
|
||||
|
||||
private final Map<File, String[]> lists;
|
||||
private final Set<File> mkdirs;
|
||||
|
||||
public Files() {
|
||||
this.lists = new HashMap<File, String[]>();
|
||||
this.mkdirs = new HashSet<File>();
|
||||
}
|
||||
|
||||
public final String[] list(File dir, FilenameFilter filter) {
|
||||
String[] list = lists.get(dir);
|
||||
|
||||
if (list == null) {
|
||||
list = dir.list();
|
||||
lists.put(dir, list);
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (String s : list)
|
||||
if (filter.accept(dir, s))
|
||||
result.add(s);
|
||||
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public final void mkdirs(File dir) {
|
||||
if (mkdirs.add(dir))
|
||||
dir.mkdirs();
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ public abstract class GeneratorWriter<W extends GeneratorWriter<W>> {
|
||||
"(?:\\[(.*)\\])" +
|
||||
"\\]", Pattern.DOTALL);
|
||||
|
||||
|
||||
private final Files files;
|
||||
private final File file;
|
||||
private final String encoding;
|
||||
private final StringBuilder sb;
|
||||
@ -86,15 +86,24 @@ public abstract class GeneratorWriter<W extends GeneratorWriter<W>> {
|
||||
private boolean newline = true;
|
||||
|
||||
protected GeneratorWriter(File file) {
|
||||
this(file, null);
|
||||
this(file, null, null);
|
||||
}
|
||||
|
||||
protected GeneratorWriter(File file, String encoding) {
|
||||
file.getParentFile().mkdirs();
|
||||
this(file, encoding, null);
|
||||
}
|
||||
|
||||
protected GeneratorWriter(File file, Files files) {
|
||||
this(file, null, files);
|
||||
}
|
||||
|
||||
protected GeneratorWriter(File file, String encoding, Files files) {
|
||||
this.files = files == null ? new Files() : files;
|
||||
this.file = file;
|
||||
this.encoding = encoding;
|
||||
this.sb = new StringBuilder();
|
||||
|
||||
this.files.mkdirs(file.getParentFile());
|
||||
}
|
||||
|
||||
public void tabString(String string) {
|
||||
@ -265,7 +274,7 @@ public abstract class GeneratorWriter<W extends GeneratorWriter<W>> {
|
||||
|
||||
// [#5892] On Windows FAT or NTFS and other case-insensitive file systems, we must
|
||||
// explicitly replace files whose case-sensitive file name has changed
|
||||
String[] list = file.getParentFile().list(new FilenameFilter() {
|
||||
String[] list = files.list(file.getParentFile(), new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.equalsIgnoreCase(file.getName()) && !name.equals(file.getName());
|
||||
|
||||
@ -244,6 +244,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
private final boolean scala;
|
||||
private final String tokenVoid;
|
||||
private final Files fileCache;
|
||||
|
||||
static {
|
||||
SQLDATATYPE_LITERAL_LOOKUP = new IdentityHashMap<DataType<?>, String>();
|
||||
@ -287,6 +288,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
this.scala = (language == SCALA);
|
||||
this.tokenVoid = (scala ? "Unit" : "void");
|
||||
this.fileCache = new Files();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -6504,7 +6506,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
// [#3880] Users may need to call this method
|
||||
protected JavaWriter newJavaWriter(File file) {
|
||||
file = fixSuffix(file);
|
||||
JavaWriter result = new JavaWriter(file, generateFullyQualifiedTypes(), targetEncoding, generateJavadoc());
|
||||
JavaWriter result = new JavaWriter(file, generateFullyQualifiedTypes(), targetEncoding, generateJavadoc(), fileCache);
|
||||
|
||||
if (generateIndentation != null)
|
||||
result.tabString(generateIndentation);
|
||||
|
||||
@ -48,7 +48,22 @@ public class JavaWriter extends GeneratorWriter<JavaWriter> {
|
||||
}
|
||||
|
||||
public JavaWriter(File file, String fullyQualifiedTypes, String encoding, boolean javadoc) {
|
||||
super(file, encoding);
|
||||
super(file, encoding, null);
|
||||
|
||||
this.className = file.getName().replaceAll("\\.(java|scala)$", "");
|
||||
this.isJava = file.getName().endsWith(".java");
|
||||
this.isScala = file.getName().endsWith(".scala");
|
||||
this.fullyQualifiedTypes = fullyQualifiedTypes == null ? null : Pattern.compile(fullyQualifiedTypes);
|
||||
this.javadoc = javadoc;
|
||||
|
||||
if (isJava)
|
||||
tabString(" ");
|
||||
else if (isScala)
|
||||
tabString(" ");
|
||||
}
|
||||
|
||||
public JavaWriter(File file, String fullyQualifiedTypes, String encoding, boolean javadoc, Files files) {
|
||||
super(file, encoding, files);
|
||||
|
||||
this.className = file.getName().replaceAll("\\.(java|scala)$", "");
|
||||
this.isJava = file.getName().endsWith(".java");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user