use of org.mybatis.generator.exception.ShellException in project generator by mybatis.
the class EclipseShellCallback method getSpecificSourceFolder.
private IPackageFragmentRoot getSpecificSourceFolder(IJavaProject javaProject, String targetProject) throws ShellException {
try {
Path path = new Path("/" + targetProject);
IPackageFragmentRoot pfr = javaProject.findPackageFragmentRoot(path);
if (pfr == null) {
StringBuffer sb = new StringBuffer();
sb.append("Cannot find source folder ");
sb.append(targetProject);
throw new ShellException(sb.toString());
}
return pfr;
} catch (CoreException e) {
throw new ShellException(e.getStatus().getMessage(), e);
}
}
use of org.mybatis.generator.exception.ShellException in project generator by mybatis.
the class EclipseShellCallback method getDirectory.
/*
* (non-Javadoc)
* @see org.mybatis.generator.api.ShellCallback#getDirectory(java.lang.String, java.lang.String)
*/
public File getDirectory(String targetProject, String targetPackage) throws ShellException {
if (targetProject.startsWith("/") || targetProject.startsWith("\\")) {
StringBuffer sb = new StringBuffer();
sb.append("targetProject ");
sb.append(targetProject);
sb.append(" is invalid - it cannot start with / or \\");
throw new ShellException(sb.toString());
}
IFolder folder = getFolder(targetProject, targetPackage);
return folder.getRawLocation().toFile();
}
use of org.mybatis.generator.exception.ShellException in project generator by mybatis.
the class EclipseShellCallback method getJavaProject.
private IJavaProject getJavaProject(String javaProjectName) throws ShellException {
IJavaProject javaProject = projects.get(javaProjectName);
if (javaProject == null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(javaProjectName);
if (project.exists()) {
boolean isJavaProject;
try {
isJavaProject = project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
throw new ShellException(e.getStatus().getMessage(), e);
}
if (isJavaProject) {
javaProject = JavaCore.create(project);
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" is not a Java project");
throw new ShellException(sb.toString());
}
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" does not exist");
throw new ShellException(sb.toString());
}
projects.put(javaProjectName, javaProject);
}
return javaProject;
}
use of org.mybatis.generator.exception.ShellException in project generator by mybatis.
the class MyBatisGenerator method writeGeneratedXmlFile.
private void writeGeneratedXmlFile(GeneratedXmlFile gxf, ProgressCallback callback) throws InterruptedException, IOException {
File targetFile;
String source;
try {
File directory = shellCallback.getDirectory(gxf.getTargetProject(), gxf.getTargetPackage());
targetFile = new File(directory, gxf.getFileName());
if (targetFile.exists()) {
if (gxf.isMergeable()) {
source = XmlFileMergerJaxp.getMergedSource(gxf, targetFile);
} else if (shellCallback.isOverwriteEnabled()) {
source = gxf.getFormattedContent();
warnings.add(getString(//$NON-NLS-1$
"Warning.11", targetFile.getAbsolutePath()));
} else {
source = gxf.getFormattedContent();
targetFile = getUniqueFileName(directory, gxf.getFileName());
warnings.add(getString("Warning.2", //$NON-NLS-1$
targetFile.getAbsolutePath()));
}
} else {
source = gxf.getFormattedContent();
}
callback.checkCancel();
callback.startTask(getString("Progress.15", //$NON-NLS-1$
targetFile.getName()));
//$NON-NLS-1$
writeFile(targetFile, source, "UTF-8");
} catch (ShellException e) {
warnings.add(e.getMessage());
}
}
use of org.mybatis.generator.exception.ShellException in project generator by mybatis.
the class MyBatisGenerator method writeGeneratedJavaFile.
private void writeGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback callback) throws InterruptedException, IOException {
File targetFile;
String source;
try {
File directory = shellCallback.getDirectory(gjf.getTargetProject(), gjf.getTargetPackage());
targetFile = new File(directory, gjf.getFileName());
if (targetFile.exists()) {
if (shellCallback.isMergeSupported()) {
source = shellCallback.mergeJavaFile(gjf.getFormattedContent(), targetFile, MergeConstants.OLD_ELEMENT_TAGS, gjf.getFileEncoding());
} else if (shellCallback.isOverwriteEnabled()) {
source = gjf.getFormattedContent();
warnings.add(getString(//$NON-NLS-1$
"Warning.11", targetFile.getAbsolutePath()));
} else {
source = gjf.getFormattedContent();
targetFile = getUniqueFileName(directory, gjf.getFileName());
warnings.add(getString("Warning.2", //$NON-NLS-1$
targetFile.getAbsolutePath()));
}
} else {
source = gjf.getFormattedContent();
}
callback.checkCancel();
callback.startTask(getString("Progress.15", //$NON-NLS-1$
targetFile.getName()));
writeFile(targetFile, source, gjf.getFileEncoding());
} catch (ShellException e) {
warnings.add(e.getMessage());
}
}
Aggregations