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 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
24 * the generator to work. A "shell" is defined as the execution environment (i.e. an
25 * Eclipse plugin, and Ant task, a Maven Mojo, etc.)
26 *
27 * @author Jeff Butler
28 */
29 public interface ShellCallback {
30
31 /**
32 * This method is called to ask the shell to resolve a project/package combination into a directory on the file
33 * system. This method is called repeatedly (once for each generated file), so it would be wise for an implementing
34 * class to cache results.
35 *
36 * <p>The returned <code>java.io.File</code> object:
37 * <ul>
38 * <li>Must be a directory</li>
39 * <li>Must exist</li>
40 * </ul>
41 *
42 * <p>The default shell callback interprets both values as directories and simply concatenates the two values to
43 * generate the default directory.
44 *
45 * @param targetProject
46 * the target project
47 * @param targetPackage
48 * the target package
49 *
50 * @return the directory (must exist)
51 *
52 * @throws ShellException
53 * if the project/package cannot be resolved into a directory on the file system. In this case, the
54 * generator will not save the file it is currently working on. The generator will add the exception
55 * message to the list of warnings automatically.
56 */
57 File getDirectory(String targetProject, String targetPackage)
58 throws ShellException;
59
60 /**
61 * After all files are saved to the file system, this method is called
62 * once for each unique project affected by the generation run.
63 * This method is useful if your IDE needs to be informed that file
64 * system objects have been created or updated. If you are running
65 * outside an IDE, your implementation need not do anything in this
66 * method.
67 *
68 * @param project the project to be refreshed
69 */
70 default void refreshProject(String project) {}
71 }