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

mybatis / generator / 1646

21 Apr 2025 10:17PM UTC coverage: 88.157% (-0.2%) from 88.328%
1646

push

github

hazendaz
[ci] Run auto formatting

2518 of 3412 branches covered (73.8%)

994 of 1117 new or added lines in 164 files covered. (88.99%)

23 existing lines in 12 files now uncovered.

10578 of 11999 relevant lines covered (88.16%)

0.88 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/api/ShellCallback.java
1
/*
2
 *    Copyright 2006-2025 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.api;
17

18
import java.io.File;
19

20
import org.mybatis.generator.exception.ShellException;
21

22
/**
23
 * This interface defines methods that a shell should support to enable the generator to work. A "shell" is defined as
24
 * the execution environment (i.e. an Eclipse plugin, and Ant task, a NetBeans plugin, etc.)
25
 * <p>
26
 * The default ShellCallback that is very low function and does not support the merging of Java files. The default shell
27
 * callback is appropriate for use in well controlled environments where no changes made to generated Java files.
28
 *
29
 * @author Jeff Butler
30
 */
31
public interface ShellCallback {
32

33
    /**
34
     * This method is called to ask the shell to resolve a project/package combination into a directory on the file
35
     * system. This method is called repeatedly (once for each generated file), so it would be wise for an implementing
36
     * class to cache results.
37
     * <p>
38
     * The returned <code>java.io.File</code> object:
39
     * <ul>
40
     * <li>Must be a directory</li>
41
     * <li>Must exist</li>
42
     * </ul>
43
     * <p>
44
     * The default shell callback interprets both values as directories and simply concatenates the two values to
45
     * generate the default directory.
46
     *
47
     * @param targetProject
48
     *            the target project
49
     * @param targetPackage
50
     *            the target package
51
     *
52
     * @return the directory (must exist)
53
     *
54
     * @throws ShellException
55
     *             if the project/package cannot be resolved into a directory on the file system. In this case, the
56
     *             generator will not save the file it is currently working on. The generator will add the exception
57
     *             message to the list of warnings automatically.
58
     */
59
    File getDirectory(String targetProject, String targetPackage) throws ShellException;
60

61
    /**
62
     * This method is called if a newly generated Java file would overwrite an existing file. This method should return
63
     * the merged source (formatted). The generator will write the merged source as-is to the file system.
64
     * <p>
65
     * A merge typically follows these steps:
66
     * <ol>
67
     * <li>Delete any methods/fields in the existing file that have the specified JavaDoc tag</li>
68
     * <li>Add any new super interfaces from the new file into the existing file</li>
69
     * <li>Make sure that the existing file's super class matches the new file</li>
70
     * <li>Make sure that the existing file is of the same type as the existing file (either interface or class)</li>
71
     * <li>Add any new imports from the new file into the existing file</li>
72
     * <li>Add all methods and fields from the new file into the existing file</li>
73
     * <li>Format the resulting source string</li>
74
     * </ol>
75
     * <p>
76
     * This method is called only if you return <code>true</code> from <code>isMergeSupported()</code>.
77
     *
78
     * @param newFileSource
79
     *            the source of the newly generated Java file
80
     * @param existingFile
81
     *            the existing Java file
82
     * @param javadocTags
83
     *            the JavaDoc tags that denotes which methods and fields in the old file to delete (if the Java element
84
     *            has any of these tags, the element is eligible for merge)
85
     * @param fileEncoding
86
     *            the file encoding for reading existing Java files. Can be null, in which case the platform default
87
     *            encoding will be used.
88
     *
89
     * @return the merged source, properly formatted. The source will be saved exactly as returned from this method.
90
     *
91
     * @throws ShellException
92
     *             if the file cannot be merged for some reason. If this exception is thrown, nothing will be saved and
93
     *             the existing file will remain undisturbed. The generator will add the exception message to the list
94
     *             of warnings automatically.
95
     */
96
    default String mergeJavaFile(String newFileSource, File existingFile, String[] javadocTags, String fileEncoding)
97
            throws ShellException {
UNCOV
98
        throw new UnsupportedOperationException();
×
99
    }
100

101
    /**
102
     * After all files are saved to the file system, this method is called once for each unique project that was
103
     * affected by the generation run. This method is useful if your IDE needs to be informed that file system objects
104
     * have been created or updated. If you are running outside an IDE, your implementation need not do anything in this
105
     * method.
106
     *
107
     * @param project
108
     *            the project to be refreshed
109
     */
110
    default void refreshProject(String project) {
NEW
111
    }
×
112

113
    /**
114
     * Return true if the callback supports Java merging, otherwise false. The <code>mergeJavaFile()</code> method will
115
     * be called only if this method returns <code>true</code>.
116
     *
117
     * @return a boolean specifying whether Java merge is supported or not
118
     */
119
    default boolean isMergeSupported() {
120
        return false;
×
121
    }
122

123
    /**
124
     * Return true if the generator should overwrite an existing file if one exists. This method will be called only if
125
     * <code>isMergeSupported()</code> returns <code>false</code> and a file exists that would be overwritten by a
126
     * generated file. If you return <code>true</code>, then we will log a warning specifying what file was overwritten.
127
     *
128
     * @return true if you want to overwrite existing files
129
     */
130
    boolean isOverwriteEnabled();
131
}
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

© 2025 Coveralls, Inc