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

mybatis / generator / 2213

14 May 2026 03:10PM UTC coverage: 91.803% (-0.04%) from 91.84%
2213

push

github

web-flow
Merge pull request #1514 from jeffgbutler/additive-merger

Allow Configuration for the Java Merger

2519 of 3223 branches covered (78.16%)

311 of 325 new or added lines in 24 files covered. (95.69%)

11 existing lines in 4 files now uncovered.

12208 of 13298 relevant lines covered (91.8%)

0.92 hits per line

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

75.68
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/config/Configuration.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.config;
17

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

21
import java.util.ArrayList;
22
import java.util.List;
23
import java.util.Optional;
24

25
import org.jspecify.annotations.Nullable;
26
import org.mybatis.generator.exception.InvalidConfigurationException;
27

28
public class Configuration {
29
    private final List<Context> contexts;
30
    private final List<String> classPathEntries;
31
    private final @Nullable IndentationConfiguration indentationConfiguration;
32
    private final @Nullable JavaMergeConfiguration javaMergeConfiguration;
33

34
    private Configuration(Builder builder) {
1✔
35
        contexts = builder.contexts;
1✔
36
        classPathEntries = builder.classPathEntries;
1✔
37
        indentationConfiguration = builder.indentationConfiguration;
1✔
38
        javaMergeConfiguration = builder.javaMergeConfiguration;
1✔
39
    }
1✔
40

41
    public List<String> getClassPathEntries() {
42
        return classPathEntries;
1✔
43
    }
44

45
    public List<Context> getContexts() {
46
        return contexts;
1✔
47
    }
48

49
    public Optional<IndentationConfiguration> getIndentationConfiguration() {
50
        return Optional.ofNullable(indentationConfiguration);
1✔
51
    }
52

53
    public Optional<JavaMergeConfiguration> getJavaMergeConfiguration() {
NEW
54
        return Optional.ofNullable(javaMergeConfiguration);
×
55
    }
56

57
    /**
58
     * This method does a simple validation, it makes sure that all required fields have been filled in and that all
59
     * implementation classes exist and are of the proper type. It does not do any more complex operations such as
60
     * validating that database tables exist or validating that named columns exist
61
     *
62
     * @throws InvalidConfigurationException
63
     *             the invalid configuration exception
64
     */
65
    public void validate() throws InvalidConfigurationException {
66
        List<String> errors = new ArrayList<>();
1✔
67

68
        for (String classPathEntry : classPathEntries) {
1!
69
            if (!stringHasValue(classPathEntry)) {
×
70
                errors.add(getString("ValidationError.19")); //$NON-NLS-1$
×
71
                // only need to state this error once
72
                break;
×
73
            }
74
        }
×
75

76
        if (contexts.isEmpty()) {
1!
77
            errors.add(getString("ValidationError.11")); //$NON-NLS-1$
×
78
        } else {
79
            for (Context context : contexts) {
1✔
80
                context.validate(errors);
1✔
81
            }
1✔
82
        }
83

84
        if (!errors.isEmpty()) {
1✔
85
            throw new InvalidConfigurationException(getString("ValidationError.32"), errors); //$NON-NLS-1$
1✔
86
        }
87
    }
1✔
88

89
    public static class Builder {
1✔
90
        private final List<Context> contexts = new ArrayList<>();
1✔
91
        private final List<String> classPathEntries = new ArrayList<>();
1✔
92
        private @Nullable IndentationConfiguration indentationConfiguration;
93
        private @Nullable JavaMergeConfiguration javaMergeConfiguration;
94

95
        public Builder withContext(Context context) {
96
            contexts.add(context);
1✔
97
            return this;
1✔
98
        }
99

100
        public Builder withClassPathEntry(@Nullable  String classPathEntry) {
101
            if (classPathEntry != null) {
×
102
                classPathEntries.add(classPathEntry);
×
103
            }
104
            return this;
×
105
        }
106

107
        public Builder withIndentationConfiguration(IndentationConfiguration indentationConfiguration) {
108
            this.indentationConfiguration = indentationConfiguration;
1✔
109
            return this;
1✔
110
        }
111

112
        public Builder withJavaMergeConfiguration(JavaMergeConfiguration javaMergeConfiguration) {
113
            this.javaMergeConfiguration = javaMergeConfiguration;
1✔
114
            return this;
1✔
115
        }
116

117
        public Configuration build() {
118
            return new Configuration(this);
1✔
119
        }
120
    }
121
}
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