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

mybatis / generator / 1722

06 Jul 2025 06:38PM UTC coverage: 88.195% (-0.1%) from 88.307%
1722

push

github

hazendaz
Setup subproject for new Java File Merger

2518 of 3420 branches covered (73.63%)

0 of 16 new or added lines in 3 files covered. (0.0%)

73 existing lines in 3 files now uncovered.

11192 of 12690 relevant lines covered (88.2%)

0.88 hits per line

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

11.54
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/internal/DefaultShellCallback.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.internal;
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.file.Files;
23
import java.nio.file.Path;
24
import java.util.Objects;
25
import java.util.StringTokenizer;
26

27
import org.mybatis.generator.api.JavaFileMerger;
28
import org.mybatis.generator.api.ShellCallback;
29
import org.mybatis.generator.exception.ShellException;
30

31
public class DefaultShellCallback implements ShellCallback {
32

33
    private final boolean overwrite;
34
    private JavaFileMerger javaFileMerger;
35

36
    public DefaultShellCallback(boolean overwrite) {
37
        super();
1✔
38
        this.overwrite = overwrite;
1✔
39
    }
1✔
40

41
    public void setJavaFileMerger(JavaFileMerger javaFileMerger) {
NEW
UNCOV
42
        this.javaFileMerger = Objects.requireNonNull(javaFileMerger);
×
NEW
UNCOV
43
    }
×
44

45
    @Override
46
    public File getDirectory(String targetProject, String targetPackage) throws ShellException {
47
        // targetProject is interpreted as a directory that must already exist
48
        //
49
        // targetPackage is interpreted as a subdirectory, but in package
50
        // format (with dots instead of slashes). The subdirectory will be
51
        // created if it does not already exist
52

53
        Path targetProjectDirectory = Path.of(targetProject);
×
54
        if (!Files.isDirectory(targetProjectDirectory)) {
×
55
            throw new ShellException(getString("Warning.9", //$NON-NLS-1$
×
56
                    targetProject));
57
        }
58

59
        StringBuilder sb = new StringBuilder();
×
60
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
×
UNCOV
61
        while (st.hasMoreTokens()) {
×
62
            sb.append(st.nextToken());
×
63
            sb.append(File.separatorChar);
×
64
        }
65

66
        Path directory = targetProjectDirectory.resolve(sb.toString());
×
UNCOV
67
        if (!Files.isDirectory(directory)) {
×
68
            try {
69
                Files.createDirectories(directory);
×
UNCOV
70
            } catch (IOException e) {
×
UNCOV
71
                throw new ShellException(getString("Warning.10", //$NON-NLS-1$
×
UNCOV
72
                        directory.toFile().getAbsolutePath()));
×
UNCOV
73
            }
×
74
        }
75

UNCOV
76
        return directory.toFile();
×
77
    }
78

79
    @Override
80
    public boolean isMergeSupported() {
NEW
UNCOV
81
        return javaFileMerger != null;
×
82
    }
83

84
    @Override
85
    public boolean isOverwriteEnabled() {
UNCOV
86
        return overwrite;
×
87
    }
88

89
    @Override
90
    public String mergeJavaFile(String newFileSource,
91
            File existingFile, String[] javadocTags, String fileEncoding)
92
            throws ShellException {
NEW
UNCOV
93
        if (javaFileMerger == null) {
×
NEW
UNCOV
94
            throw new UnsupportedOperationException();
×
95
        } else {
NEW
UNCOV
96
            return javaFileMerger.mergeJavaFile(newFileSource, existingFile, javadocTags, fileEncoding);
×
97
        }
98
    }
99
}
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