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
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -105,6 +105,22 @@ public List<GeneratedKotlinFile> contextGenerateAdditionalKotlinFiles(Introspect
.collect(Collectors.toList());
}

@Override
public List<GeneratedFile> contextGenerateAdditionalFiles() {
return plugins.stream()
.map(Plugin::contextGenerateAdditionalFiles)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Override
public List<GeneratedFile> contextGenerateAdditionalFiles(IntrospectedTable introspectedTable) {
return plugins.stream()
.map(p -> p.contextGenerateAdditionalFiles(introspectedTable))
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
return plugins.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -79,4 +79,6 @@ public String toString() {
* @return true, if is mergeable
*/
public abstract boolean isMergeable();

public abstract String getFileEncoding();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -78,6 +78,7 @@ public boolean isMergeable() {
return true;
}

@Override
public String getFileEncoding() {
return fileEncoding;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -55,6 +55,7 @@ public boolean isMergeable() {
return false;
}

@Override
public String getFileEncoding() {
return fileEncoding;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -63,4 +63,9 @@ public boolean isMergeable() {
public void setMergeable(boolean isMergeable) {
this.isMergeable = isMergeable;
}

@Override
public String getFileEncoding() {
return "UTF-8"; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -66,6 +66,11 @@ public class MyBatisGenerator {

private final List<GeneratedKotlinFile> generatedKotlinFiles = new ArrayList<>();

/**
* Any kind of generated file generated by plugin methods contextGenerateAdditionalFiles
*/
private final List<GeneratedFile> otherGeneratedFiles = new ArrayList<>();

private final List<String> warnings;

private final Set<String> projects = new HashSet<>();
Expand Down Expand Up @@ -261,7 +266,7 @@ public void generate(ProgressCallback callback, Set<String> contextIds,

for (Context context : contextsToRun) {
context.generateFiles(callback, generatedJavaFiles,
generatedXmlFiles, generatedKotlinFiles, warnings);
generatedXmlFiles, generatedKotlinFiles, otherGeneratedFiles, warnings);
}

// now save the files
Expand All @@ -281,7 +286,12 @@ public void generate(ProgressCallback callback, Set<String> contextIds,

for (GeneratedKotlinFile gkf : generatedKotlinFiles) {
projects.add(gkf.getTargetProject());
writeGeneratedKotlinFile(gkf, callback);
writeGeneratedFile(gkf, callback);
}

for (GeneratedFile gf : otherGeneratedFiles) {
projects.add(gf.getTargetProject());
writeGeneratedFile(gf, callback);
}

for (String project : projects) {
Expand Down Expand Up @@ -330,34 +340,34 @@ private void writeGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback call
}
}

private void writeGeneratedKotlinFile(GeneratedKotlinFile gkf, ProgressCallback callback)
private void writeGeneratedFile(GeneratedFile gf, ProgressCallback callback)
throws InterruptedException, IOException {
File targetFile;
String source;
try {
File directory = shellCallback.getDirectory(gkf
.getTargetProject(), gkf.getTargetPackage());
targetFile = new File(directory, gkf.getFileName());
File directory = shellCallback.getDirectory(gf
.getTargetProject(), gf.getTargetPackage());
targetFile = new File(directory, gf.getFileName());
if (targetFile.exists()) {
if (shellCallback.isOverwriteEnabled()) {
source = gkf.getFormattedContent();
source = gf.getFormattedContent();
warnings.add(getString("Warning.11", //$NON-NLS-1$
targetFile.getAbsolutePath()));
} else {
source = gkf.getFormattedContent();
targetFile = getUniqueFileName(directory, gkf
source = gf.getFormattedContent();
targetFile = getUniqueFileName(directory, gf
.getFileName());
warnings.add(getString(
"Warning.2", targetFile.getAbsolutePath())); //$NON-NLS-1$
}
} else {
source = gkf.getFormattedContent();
source = gf.getFormattedContent();
}

callback.checkCancel();
callback.startTask(getString(
"Progress.15", targetFile.getName())); //$NON-NLS-1$
writeFile(targetFile, source, gkf.getFileEncoding());
writeFile(targetFile, source, gf.getFileEncoding());
} catch (ShellException e) {
warnings.add(e.getMessage());
}
Expand Down Expand Up @@ -393,7 +403,7 @@ private void writeGeneratedXmlFile(GeneratedXmlFile gxf, ProgressCallback callba
callback.checkCancel();
callback.startTask(getString(
"Progress.15", targetFile.getName())); //$NON-NLS-1$
writeFile(targetFile, source, "UTF-8"); //$NON-NLS-1$
writeFile(targetFile, source, gxf.getFileEncoding());
} catch (ShellException e) {
warnings.add(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -164,6 +164,14 @@ default List<GeneratedKotlinFile> contextGenerateAdditionalKotlinFiles(Introspec
return Collections.emptyList();
}

default List<GeneratedFile> contextGenerateAdditionalFiles() {
return Collections.emptyList();
}

default List<GeneratedFile> contextGenerateAdditionalFiles(IntrospectedTable introspectedTable) {
return Collections.emptyList();
}

/**
* This method can be used to generate any additional XML file needed by
* your implementation. This method is called once, after all other XML
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -28,6 +28,7 @@

import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.ConnectionFactory;
import org.mybatis.generator.api.GeneratedFile;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.GeneratedKotlinFile;
import org.mybatis.generator.api.GeneratedXmlFile;
Expand Down Expand Up @@ -432,6 +433,7 @@ public void generateFiles(ProgressCallback callback,
List<GeneratedJavaFile> generatedJavaFiles,
List<GeneratedXmlFile> generatedXmlFiles,
List<GeneratedKotlinFile> generatedKotlinFiles,
List<GeneratedFile> otherGeneratedFiles,
List<String> warnings)
throws InterruptedException {

Expand Down Expand Up @@ -470,6 +472,8 @@ public void generateFiles(ProgressCallback callback,
.contextGenerateAdditionalXmlFiles(introspectedTable));
generatedKotlinFiles.addAll(pluginAggregator
.contextGenerateAdditionalKotlinFiles(introspectedTable));
otherGeneratedFiles.addAll(pluginAggregator
.contextGenerateAdditionalFiles(introspectedTable));
}

generatedJavaFiles.addAll(pluginAggregator
Expand All @@ -478,6 +482,8 @@ public void generateFiles(ProgressCallback callback,
.contextGenerateAdditionalXmlFiles());
generatedKotlinFiles.addAll(pluginAggregator
.contextGenerateAdditionalKotlinFiles());
otherGeneratedFiles.addAll(pluginAggregator
.contextGenerateAdditionalFiles());
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ required:</p>
<li>Added the ability to specify a MyBatis Dynamic SQL Support class name on the table configuration</li>
<li>Added a plugin to generate @CacheNamespace annotations</li>
<li>Added the ability to specify a name for the inner class generated in the MyBatis Dynamic SQL support class</li>
<li>Added plugin methods that allow generation of any arbitrary file type</li>
</ul>

<h3>Removed Items</h3>
Expand Down