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

mybatis / generator / 2027

08 Feb 2026 06:52PM UTC coverage: 89.941% (-0.02%) from 89.961%
2027

push

github

web-flow
Remove the Eclipse based Java file merger in favor of the merger in the core library (#1443)

* Remove unnecessary extra line in JavaDoc for most cases

* Support unmergeable Java files

* Generic files are never mergeable

* Remove Java merger from the Eclipse plugin

The new merger in the core project is better tested and more capable.

* Package our dependencies in a new plugin

* Remove the old core plugin

There is no need for this to be separated now. It only held the callback implementations after we removed the merger.

* Use Eclipse BND tools to keep binaries out of our source repo

* Revert a little change no longer needed

* Remove the old target platform definitions - no need to keep them around

* Remove deprecated source feature generation

Replace it with an explicit source feature

* Remove deprecated source feature generation

Replace it with an explicit source feature

* Remove unnecessary dependencies

* Restore the function where we add the Java project to the runtime classpath

This seems to have changed in more recent Eclipse versions. The project was getting added to the bootstrap classpath and not the user classpath.

* Documentation Updates

* Setup artifact signing in the release profile

* Refactor the main entry point and shell callback so that Java merging is configurable and optional

* Refactor the main entry point and shell callback so that Java merging is configurable and optional

2295 of 3073 branches covered (74.68%)

66 of 96 new or added lines in 8 files covered. (68.75%)

4 existing lines in 3 files now uncovered.

11641 of 12943 relevant lines covered (89.94%)

0.9 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/ShellRunner.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.api;
17

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

20
import java.io.IOException;
21
import java.nio.file.Files;
22
import java.nio.file.Path;
23
import java.sql.SQLException;
24
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.List;
27
import java.util.Map;
28
import java.util.Set;
29

30
import org.mybatis.generator.config.Configuration;
31
import org.mybatis.generator.config.xml.ConfigurationParser;
32
import org.mybatis.generator.exception.InvalidConfigurationException;
33
import org.mybatis.generator.exception.XMLParserException;
34
import org.mybatis.generator.internal.DefaultShellCallback;
35
import org.mybatis.generator.internal.util.StringUtility;
36

37
/**
38
 * This class allows the code generator to be run from the command line.
39
 *
40
 * @author Jeff Butler
41
 */
42
public class ShellRunner {
×
43
    private static final String CONFIG_FILE = "-configfile"; //$NON-NLS-1$
44
    private static final String OVERWRITE = "-overwrite"; //$NON-NLS-1$
45
    private static final String CONTEXT_IDS = "-contextids"; //$NON-NLS-1$
46
    private static final String TABLES = "-tables"; //$NON-NLS-1$
47
    private static final String VERBOSE = "-verbose"; //$NON-NLS-1$
48
    private static final String JAVA_MERGE_ENABLED = "-javaMergeEnabled";
49
    private static final String HELP_1 = "-?"; //$NON-NLS-1$
50
    private static final String HELP_2 = "-h"; //$NON-NLS-1$
51

52
    public static void main(String[] args) {
53
        if (args.length == 0) {
×
54
            usage();
×
55
            System.exit(0);
×
56
            return; // only to satisfy compiler, never returns
×
57
        }
58

59
        Map<String, String> arguments = parseCommandLine(args);
×
60

61
        if (arguments.containsKey(HELP_1)) {
×
62
            usage();
×
63
            System.exit(0);
×
64
            return; // only to satisfy compiler, never returns
×
65
        }
66

67
        if (!arguments.containsKey(CONFIG_FILE)) {
×
68
            writeLine(getString("RuntimeError.0")); //$NON-NLS-1$
×
69
            return;
×
70
        }
71

72
        List<String> warnings = new ArrayList<>();
×
73

74
        String configfile = arguments.get(CONFIG_FILE);
×
75
        Path configurationFile = Path.of(configfile);
×
76
        if (Files.notExists(configurationFile)) {
×
77
            writeLine(getString("RuntimeError.1", configfile)); //$NON-NLS-1$
×
78
            return;
×
79
        }
80

81
        Set<String> fullyQualifiedTables = StringUtility.tokenize(arguments.get(TABLES));
×
82

83
        Set<String> contexts = StringUtility.tokenize(arguments.get(CONTEXT_IDS));
×
84

85
        try {
86
            ConfigurationParser cp = new ConfigurationParser();
×
87
            Configuration config = cp.parseConfiguration(configurationFile.toFile());
×
88
            warnings.addAll(cp.getWarnings());
×
NEW
89
            boolean overwriteEnabled = arguments.containsKey(OVERWRITE);
×
NEW
90
            boolean javaMergeEnabled = arguments.containsKey(JAVA_MERGE_ENABLED);
×
91

92
            ProgressCallback progressCallback = arguments.containsKey(VERBOSE) ? new VerboseProgressCallback()
×
93
                    : null;
×
94

95
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator.Builder()
×
96
                    .withConfiguration(config)
×
NEW
97
                    .withShellCallback(new DefaultShellCallback())
×
98
                    .withProgressCallback(progressCallback)
×
99
                    .withContextIds(contexts)
×
100
                    .withFullyQualifiedTableNames(fullyQualifiedTables)
×
NEW
101
                    .withJavaFileMergeEnabled(javaMergeEnabled)
×
NEW
102
                    .withOverwriteEnabled(overwriteEnabled)
×
UNCOV
103
                    .build();
×
104

105
            warnings.addAll(myBatisGenerator.generateAndWrite());
×
106
        } catch (XMLParserException e) {
×
107
            writeLine(getString("Progress.3")); //$NON-NLS-1$
×
108
            writeLine();
×
109
            for (String error : e.getErrors()) {
×
110
                writeLine(error);
×
111
            }
×
112

113
            return;
×
114
        } catch (SQLException | IOException e) {
×
115
            e.printStackTrace(System.out);
×
116
            return;
×
117
        } catch (InvalidConfigurationException e) {
×
118
            writeLine(getString("Progress.16")); //$NON-NLS-1$
×
119
            for (String error : e.getErrors()) {
×
120
                writeLine(error);
×
121
            }
×
122
            return;
×
123
        } catch (InterruptedException e) {
×
124
            Thread.currentThread().interrupt();
×
125
        }
×
126

127
        for (String warning : warnings) {
×
128
            writeLine(warning);
×
129
        }
×
130

131
        if (warnings.isEmpty()) {
×
132
            writeLine(getString("Progress.4")); //$NON-NLS-1$
×
133
        } else {
134
            writeLine();
×
135
            writeLine(getString("Progress.5")); //$NON-NLS-1$
×
136
        }
137
    }
×
138

139
    private static void usage() {
140
        writeLine(getString("Usage")); //$NON-NLS-1$
×
141
    }
×
142

143
    private static void writeLine(String message) {
144
        System.out.println(message);
×
145
    }
×
146

147
    private static void writeLine() {
148
        System.out.println();
×
149
    }
×
150

151
    private static Map<String, String> parseCommandLine(String[] args) {
152
        List<String> errors = new ArrayList<>();
×
153
        Map<String, String> arguments = new HashMap<>();
×
154

155
        for (int i = 0; i < args.length; i++) {
×
156
            if (CONFIG_FILE.equalsIgnoreCase(args[i])) {
×
157
                if ((i + 1) < args.length) {
×
158
                    arguments.put(CONFIG_FILE, args[i + 1]);
×
159
                } else {
160
                    errors.add(getString(
×
161
                            "RuntimeError.19", CONFIG_FILE)); //$NON-NLS-1$
162
                }
163
                i++;
×
164
            } else if (OVERWRITE.equalsIgnoreCase(args[i])) {
×
165
                arguments.put(OVERWRITE, "Y"); //$NON-NLS-1$
×
166
            } else if (VERBOSE.equalsIgnoreCase(args[i])) {
×
167
                arguments.put(VERBOSE, "Y"); //$NON-NLS-1$
×
168
            } else if (JAVA_MERGE_ENABLED.equalsIgnoreCase(args[i])) {
×
169
                arguments.put(JAVA_MERGE_ENABLED, "Y"); //$NON-NLS-1$
×
170
            } else if (HELP_1.equalsIgnoreCase(args[i])) {
×
171
                arguments.put(HELP_1, "Y"); //$NON-NLS-1$
×
172
            } else if (HELP_2.equalsIgnoreCase(args[i])) {
×
173
                // put HELP_1 in the map here too - so we only
174
                // have to check for one entry in the mainline
175
                arguments.put(HELP_1, "Y"); //$NON-NLS-1$
×
176
            } else if (CONTEXT_IDS.equalsIgnoreCase(args[i])) {
×
177
                if ((i + 1) < args.length) {
×
178
                    arguments.put(CONTEXT_IDS, args[i + 1]);
×
179
                } else {
180
                    errors.add(getString(
×
181
                            "RuntimeError.19", CONTEXT_IDS)); //$NON-NLS-1$
182
                }
183
                i++;
×
184
            } else if (TABLES.equalsIgnoreCase(args[i])) {
×
185
                if ((i + 1) < args.length) {
×
186
                    arguments.put(TABLES, args[i + 1]);
×
187
                } else {
188
                    errors.add(getString("RuntimeError.19", TABLES)); //$NON-NLS-1$
×
189
                }
190
                i++;
×
191
            } else {
192
                errors.add(getString("RuntimeError.20", args[i])); //$NON-NLS-1$
×
193
            }
194
        }
195

196
        if (!errors.isEmpty()) {
×
197
            for (String error : errors) {
×
198
                writeLine(error);
×
199
            }
×
200

201
            System.exit(-1);
×
202
        }
203

204
        return arguments;
×
205
    }
206
}
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