Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
if (!of.isDirectory()) {
of.mkdirs();
}
String outputFilename = outputFolder + File.separator + support.destinationFilename;
String outputFilename = outputFolder + File.separator + support.destinationFilename.replace('/', File.separatorChar);
if (!config.shouldOverwrite(outputFilename)) {
LOGGER.info("Skipped overwriting " + outputFilename);
continue;
Expand Down Expand Up @@ -657,7 +657,8 @@ public List<File> generate() {
}

private File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename) throws IOException {
if(ignoreProcessor.allowsFile(new File(outputFilename.replaceAll("//", "/")))) {
String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar);
if(ignoreProcessor.allowsFile(new File(adjustedOutputFilename))) {
String templateFile = getFullTemplateFile(config, templateName);
String template = readTemplate(templateFile);
Mustache.Compiler compiler = Mustache.compiler();
Expand All @@ -672,11 +673,11 @@ public Reader getTemplate(String name) {
.defaultValue("")
.compile(template);

writeToFile(outputFilename, tmpl.execute(templateData));
return new File(outputFilename);
writeToFile(adjustedOutputFilename, tmpl.execute(templateData));
return new File(adjustedOutputFilename);
}

LOGGER.info("Skipped generation of " + outputFilename + " due to rule in .swagger-codegen-ignore");
LOGGER.info("Skipped generation of " + adjustedOutputFilename + " due to rule in .swagger-codegen-ignore");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public static Object[] factoryMethod() throws IOException {
return new Object[] {
// Matching filenames
new CodegenIgnoreProcessorTest("build.sh", "build.sh", "A file when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("build.sh", "*.sh", "A file when matching glob should ignore.").ignored(),
new CodegenIgnoreProcessorTest("src/build.sh", "*.sh", "A nested file when matching non-nested simple glob should allow.").allowed(),
new CodegenIgnoreProcessorTest("src/build.sh", "**/build.sh", "A file when matching nested files should ignore.").ignored(),
new CodegenIgnoreProcessorTest("Build.sh", "build.sh", "A file when non-matching should allow.").allowed().skipOnCondition(SystemUtils.IS_OS_WINDOWS),
new CodegenIgnoreProcessorTest("build.sh", "/build.sh", "A rooted file when matching should ignore.").ignored(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,43 @@ public void testNonMatchComplex() throws Exception {
assertFalse(actual);
}

@Test
public void testGlobbingRecursive() throws Exception {
// Arrange
final String definition = "*.txt";
final String relativePath = "path/to/some/nested/location/xyzzy.txt";

// Act
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.MATCH_ALL),
new Part(IgnoreLineParser.Token.DIRECTORY_MARKER),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);

Rule rule = new FileRule(syntax, definition);
Boolean actual = rule.matches(relativePath);

// Assert
assertTrue(actual);
}

@Test
public void testGlobbingNotRecursive() throws Exception {
// Arrange
final String definition = "*.txt";
final String relativePath = "path/to/some/nested/location/xyzzy.txt";

// Act
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);

Rule rule = new FileRule(syntax, definition);
Boolean actual = rule.matches(relativePath);

// Assert
assertFalse(actual);
}
}