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

mybatis / generator / 1666

24 May 2025 05:59PM UTC coverage: 88.307% (-0.02%) from 88.328%
1666

push

github

web-flow
Merge pull request #1312 from hazendaz/master

Use NIO classes to resolve modernizer issues

2518 of 3410 branches covered (73.84%)

0 of 44 new or added lines in 7 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

11192 of 12674 relevant lines covered (88.31%)

0.88 hits per line

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

15.0
/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.StringTokenizer;
25

26
import org.mybatis.generator.api.ShellCallback;
27
import org.mybatis.generator.exception.ShellException;
28

29
public class DefaultShellCallback implements ShellCallback {
30

31
    private final boolean overwrite;
32

33
    public DefaultShellCallback(boolean overwrite) {
34
        super();
1✔
35
        this.overwrite = overwrite;
1✔
36
    }
1✔
37

38
    @Override
39
    public File getDirectory(String targetProject, String targetPackage) throws ShellException {
40
        // targetProject is interpreted as a directory that must already exist
41
        //
42
        // targetPackage is interpreted as a subdirectory, but in package
43
        // format (with dots instead of slashes). The subdirectory will be
44
        // created if it does not already exist
45

NEW
46
        Path targetProjectDirectory = Path.of(targetProject);
×
NEW
47
        if (!Files.isDirectory(targetProjectDirectory)) {
×
UNCOV
48
            throw new ShellException(getString("Warning.9", //$NON-NLS-1$
×
49
                    targetProject));
50
        }
51

52
        StringBuilder sb = new StringBuilder();
×
53
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
×
54
        while (st.hasMoreTokens()) {
×
55
            sb.append(st.nextToken());
×
56
            sb.append(File.separatorChar);
×
57
        }
58

NEW
59
        Path directory = targetProjectDirectory.resolve(sb.toString());
×
NEW
60
        if (!Files.isDirectory(directory)) {
×
61
            try {
NEW
62
                Files.createDirectories(directory);
×
NEW
63
            } catch (IOException e) {
×
64
                throw new ShellException(getString("Warning.10", //$NON-NLS-1$
×
NEW
65
                        directory.toFile().getAbsolutePath()));
×
UNCOV
66
            }
×
67
        }
68

NEW
69
        return directory.toFile();
×
70
    }
71

72
    @Override
73
    public boolean isOverwriteEnabled() {
74
        return overwrite;
×
75
    }
76
}
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