• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / generator / 2142

06 Apr 2026 03:19PM UTC coverage: 91.678% (-0.1%) from 91.775%
2142

push

github

web-flow
Merge pull request #1487 from jeffgbutler/merge-exception

Add a new exception for merge errors, improve exception handling in general

2425 of 3124 branches covered (77.62%)

19 of 44 new or added lines in 13 files covered. (43.18%)

7 existing lines in 4 files now uncovered.

11887 of 12966 relevant lines covered (91.68%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/merge/java/JavaFileMerger.java
1
/*
2
 *    Copyright 2006-2026 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.mybatis.generator.merge.java;
17

18
import static org.mybatis.generator.internal.util.messages.Messages.getString;
19

20
import java.io.File;
21
import java.io.IOException;
22
import java.nio.charset.Charset;
23
import java.nio.charset.StandardCharsets;
24
import java.nio.file.Files;
25

26
import org.jspecify.annotations.Nullable;
27
import org.mybatis.generator.exception.MergeException;
28

29
@FunctionalInterface
30
public interface JavaFileMerger {
31

32
    /**
33
     * Merge a newly generated Java file with an existing Java file.
34
     *
35
     * @param newFileContent the content of the newly generated Java file
36
     * @param existingFile the existing Java file
37
     * @param fileEncoding the file encoding for reading existing Java files
38
     * @return the merged source, properly formatted
39
     * @throws MergeException if the file cannot be merged for some reason
40
     */
41
    default String getMergedSource(String newFileContent, File existingFile,
42
                                  @Nullable String fileEncoding) throws MergeException {
43
        try {
44
            String existingFileContent = readFileContent(existingFile, fileEncoding);
×
45
            return getMergedSource(newFileContent, existingFileContent);
×
46
        } catch (IOException e) {
×
NEW
47
            throw new MergeException(getString("Warning.32", existingFile.getName()), e); //$NON-NLS-1$
×
48
        }
49
    }
50

51
    /**
52
     * Merge a newly generated Java file with existing Java file content.
53
     *
54
     * @param newFileContent the content of the newly generated Java file
55
     * @param existingFileContent the content of the existing Java file
56
     * @return the merged source, properly formatted
57
     * @throws MergeException if the file cannot be merged for some reason
58
     */
59
    String getMergedSource(String newFileContent, String existingFileContent) throws MergeException;
60

61
    private String readFileContent(File file, @Nullable String fileEncoding) throws IOException {
62
        if (fileEncoding != null) {
×
63
            return Files.readString(file.toPath(), Charset.forName(fileEncoding));
×
64
        } else {
65
            return Files.readString(file.toPath(), StandardCharsets.UTF_8);
×
66
        }
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc