org.mybatis.generator.exception.ShellException Java Examples
The following examples show how to use
org.mybatis.generator.exception.ShellException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyBatisGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
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 = shellCallback.mergeXmlFile(gxf, targetFile); } else { source = checkInner(targetFile, directory, gxf); } } else { source = gxf.getFormattedContent(); } callback.checkCancel(); callback.startTask(getString("Progress.15", targetFile.getName())); writeFile(targetFile, source, "UTF-8"); } catch (ShellException e) { warnings.add(e.getMessage()); } }
Example #2
Source File: DomWriter.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
/** * Write. * * @param node * the node * @throws ShellException * the shell exception */ protected void write(DocumentType node) throws ShellException { printWriter.print("<!DOCTYPE "); //$NON-NLS-1$ printWriter.print(node.getName()); String publicId = node.getPublicId(); String systemId = node.getSystemId(); if (publicId != null) { printWriter.print(" PUBLIC \""); //$NON-NLS-1$ printWriter.print(publicId); printWriter.print("\" \""); //$NON-NLS-1$ printWriter.print(systemId); printWriter.print('\"'); } else if (systemId != null) { printWriter.print(" SYSTEM \""); //$NON-NLS-1$ printWriter.print(systemId); printWriter.print('"'); } String internalSubset = node.getInternalSubset(); if (internalSubset != null) { printWriter.println(" ["); //$NON-NLS-1$ printWriter.print(internalSubset); printWriter.print(']'); } printWriter.println('>'); }
Example #3
Source File: DomWriter.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
protected void write(DocumentType node) throws ShellException { printWriter.print("<!DOCTYPE "); //$NON-NLS-1$ printWriter.print(node.getName()); String publicId = node.getPublicId(); String systemId = node.getSystemId(); if (publicId != null) { printWriter.print(" PUBLIC \""); //$NON-NLS-1$ printWriter.print(publicId); printWriter.print("\" \""); //$NON-NLS-1$ printWriter.print(systemId); printWriter.print('\"'); } else if (systemId != null) { printWriter.print(" SYSTEM \""); //$NON-NLS-1$ printWriter.print(systemId); printWriter.print('"'); } String internalSubset = node.getInternalSubset(); if (internalSubset != null) { printWriter.println(" ["); //$NON-NLS-1$ printWriter.print(internalSubset); printWriter.print(']'); } printWriter.println('>'); }
Example #4
Source File: MyShellCallback.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public String mergeXmlFile(GeneratedXmlFile gxf, File targetFile) throws ShellException { try { return getMergedSource(new InputSource(new StringReader(gxf.getFormattedContent())), new InputSource(new InputStreamReader(new FileInputStream(targetFile), StandardCharsets.UTF_8)), targetFile.getName()); } catch (IOException | SAXException | ParserConfigurationException e) { throw new ShellException(getString("Warning.13", targetFile.getName()), e); } }
Example #5
Source File: DomWriter.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public synchronized String toString(Document document) throws ShellException { StringWriter sw = new StringWriter(); printWriter = new PrintWriter(sw); write(document); String s = sw.toString(); return s; }
Example #6
Source File: DefaultShellCallback.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
public File getDirectory(String targetProject, String targetPackage) throws ShellException { // targetProject is interpreted as a directory that must exist // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be // created // if it does not already exist File project = new File(targetProject); if (!project.isDirectory()) { throw new ShellException(getString("Warning.9", //$NON-NLS-1$ targetProject)); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(getString("Warning.10", //$NON-NLS-1$ directory.getAbsolutePath())); } } return directory; }
Example #7
Source File: DomWriter.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Write. * * @param node * the node * @throws ShellException * the shell exception */ protected void write(Element node) throws ShellException { printWriter.print('<'); printWriter.print(node.getNodeName()); Attr attrs[] = sortAttributes(node.getAttributes()); for (Attr attr : attrs) { printWriter.print(' '); printWriter.print(attr.getNodeName()); printWriter.print("=\""); //$NON-NLS-1$ normalizeAndPrint(attr.getNodeValue(), true); printWriter.print('"'); } if (node.getChildNodes().getLength() == 0) { printWriter.print(" />"); //$NON-NLS-1$ printWriter.flush(); } else { printWriter.print('>'); printWriter.flush(); Node child = node.getFirstChild(); while (child != null) { writeAnyNode(child); child = child.getNextSibling(); } printWriter.print("</"); //$NON-NLS-1$ printWriter.print(node.getNodeName()); printWriter.print('>'); printWriter.flush(); } }
Example #8
Source File: DomWriter.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Write. * * @param node * the node * @throws ShellException * the shell exception */ protected void write(Document node) throws ShellException { isXML11 = "1.1".equals(getVersion(node)); //$NON-NLS-1$ if (isXML11) { printWriter.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ } else { printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ } printWriter.flush(); write(node.getDoctype()); write(node.getDocumentElement()); }
Example #9
Source File: DomWriter.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
protected void write(Document node) throws ShellException { isXML11 = "1.1".equals(getVersion(node)); //$NON-NLS-1$ if (isXML11) { printWriter.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ } else { printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ } printWriter.flush(); write(node.getDoctype()); write(node.getDocumentElement()); }
Example #10
Source File: DomWriter.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
protected void write(Element node) throws ShellException { printWriter.print('<'); printWriter.print(node.getNodeName()); Attr attrs[] = sortAttributes(node.getAttributes()); for (Attr attr : attrs) { printWriter.print(' '); printWriter.print(attr.getNodeName()); printWriter.print("=\""); //$NON-NLS-1$ normalizeAndPrint(attr.getNodeValue(), true); printWriter.print('"'); } if (node.getChildNodes().getLength() == 0) { printWriter.print(" />"); //$NON-NLS-1$ printWriter.flush(); } else { printWriter.print('>'); printWriter.flush(); Node child = node.getFirstChild(); while (child != null) { writeAnyNode(child); child = child.getNextSibling(); } printWriter.print("</"); //$NON-NLS-1$ printWriter.print(node.getNodeName()); printWriter.print('>'); printWriter.flush(); } }
Example #11
Source File: DefaultShellCallback.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public File getDirectory(String targetProject, String targetPackage) throws ShellException { // targetProject is interpreted as a directory that must exist // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be // created // if it does not already exist File project = new File(targetProject); if (!project.isDirectory()) { throw new ShellException(getString("Warning.9", //$NON-NLS-1$ targetProject)); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(getString("Warning.10", //$NON-NLS-1$ directory.getAbsolutePath())); } } return directory; }
Example #12
Source File: AbstractShellCallback.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
public File getDirectory(String targetProject, String targetPackage) throws ShellException { // targetProject is interpreted as a directory that must exist // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be // created // if it does not already exist File project = new File(targetProject); if (!project.isDirectory()) { throw new ShellException(getString("Warning.9", targetProject)); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(getString("Warning.10", directory.getAbsolutePath())); } } return directory; }
Example #13
Source File: ContentMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
private File getTargetFile(String packiage, String fileName) throws ShellException { File root = new File(this.rootDir); if (!root.exists()) { root.mkdirs(); } File directory = callback.getDirectory(rootDir, packiage); File targetFile = new File(directory, fileName); return targetFile; }
Example #14
Source File: XmlFileMergerJaxp.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public static String getMergedSource(GeneratedXmlFile generatedXmlFile, File existingFile) throws ShellException { try { return getMergedSource(new InputSource(new StringReader(generatedXmlFile.getFormattedContent())), new InputSource(new InputStreamReader(new FileInputStream(existingFile), StandardCharsets.UTF_8)), existingFile.getName()); } catch (IOException | SAXException | ParserConfigurationException e) { throw new ShellException(getString("Warning.13", existingFile.getName()), e); } }
Example #15
Source File: ContentMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { SqlMapGeneratorConfiguration smgc = context.getSqlMapGeneratorConfiguration(); try { Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); File targetFile = getTargetFile(smgc.getTargetPackage(), sqlMap.getFileName()); if (!targetFile.exists()) { // 第一次生成直接使用当前生成的文件 return true; } visitAndMerge(document, targetFile); } catch (ShellException | IOException | IllegalAccessException | DocumentException e) { e.printStackTrace(); } return true; }
Example #16
Source File: XMLMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
/** * 从DefaultShellCallback中借用的解析文件夹的函数 * * @param targetProject target project * @param targetPackage target package * @return file instance * @throws ShellException Cannot get infos form environment */ public File getDirectory(String targetProject, String targetPackage) throws ShellException { // targetProject is interpreted as a directory that must exist // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be // created // if it does not already exist File project = new File(targetProject); if (!project.isDirectory()) { throw new ShellException(getString("Warning.9", //$NON-NLS-1$ targetProject)); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(getString("Warning.10", //$NON-NLS-1$ directory.getAbsolutePath())); } } return directory; }
Example #17
Source File: DefaultShellCallback.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public File getDirectory(String targetProject, String targetPackage) throws ShellException { // targetProject is interpreted as a directory that must exist // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be // created // if it does not already exist File project = new File(targetProject); if (!project.isDirectory()) { throw new ShellException(getString("Warning.9", targetProject)); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(getString("Warning.10", directory.getAbsolutePath())); } } return directory; }
Example #18
Source File: DomWriter.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
protected void write(Element node) throws ShellException { printWriter.print('<'); printWriter.print(node.getNodeName()); Attr[] attrs = sortAttributes(node.getAttributes()); for (Attr attr : attrs) { printWriter.print(' '); printWriter.print(attr.getNodeName()); printWriter.print("=\""); normalizeAndPrint(attr.getNodeValue(), true); printWriter.print('"'); } if (node.getChildNodes().getLength() == 0) { printWriter.print(" />"); printWriter.flush(); } else { printWriter.print('>'); printWriter.flush(); Node child = node.getFirstChild(); while (child != null) { writeAnyNode(child); child = child.getNextSibling(); } printWriter.print("</"); printWriter.print(node.getNodeName()); printWriter.print('>'); printWriter.flush(); } }
Example #19
Source File: DomWriter.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
protected void write(Document node) throws ShellException { isXML11 = "1.1".equals(getVersion(node)); if (isXML11) { printWriter.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); } else { printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); } printWriter.flush(); write(node.getDoctype()); write(node.getDocumentElement()); }
Example #20
Source File: XMLMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
/** * 根据xml文件所属的包名获取相应的文件 * * @param packiage package declaration * @param fileName target file name * @throws ShellException Cannot get infos form environment */ private File getTargetFile(String packiage, String fileName) throws ShellException { File root = new File(this.rootDir); if (!root.exists()) { root.mkdirs(); } File directory = getDirectory(rootDir, packiage); File targetFile = new File(directory, fileName); return targetFile; }
Example #21
Source File: DomWriter.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public synchronized String toString(Document document) throws ShellException { StringWriter sw = new StringWriter(); printWriter = new PrintWriter(sw); write(document); return sw.toString(); }
Example #22
Source File: MyBatisGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
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.getOldElementTags(), gjf.getFileEncoding()); } else { source = checkInner(targetFile, directory, gjf); } } else { source = gjf.getFormattedContent(); } callback.checkCancel(); callback.startTask(getString("Progress.15", targetFile.getName())); writeFile(targetFile, source, gjf.getFileEncoding()); } catch (ShellException e) { warnings.add(e.getMessage()); } }
Example #23
Source File: XMLMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { SqlMapGeneratorConfiguration smgc = context.getSqlMapGeneratorConfiguration(); try { Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); File targetFile = getTargetFile(smgc.getTargetPackage(), sqlMap.getFileName()); if (!targetFile.exists()) { // 第一次生成直接使用当前生成的文件 return true; } visitAndMerge(document, targetFile); } catch (ShellException | IOException | IllegalAccessException | DocumentException e) { e.printStackTrace(); } return true; }
Example #24
Source File: MergeSupportedShellCallback.java From dolphin with Apache License 2.0 | 5 votes |
@Override public String mergeJavaFile(String newFileSource, String existingFileFullPath, String[] javadocTags, String fileEncoding) throws ShellException { String mergedFileSource = newFileSource; LOGGER.info("merge java source file for {}", existingFileFullPath); try { mergedFileSource = CompilationUnitMerger.merge(newFileSource, readFileToString(getFile(existingFileFullPath))); } catch (Exception e) { LOGGER.info("java source merge failed: {}", e); throw new ShellException(e); } return mergedFileSource; }
Example #25
Source File: MavenShellCallback.java From dolphin with Apache License 2.0 | 4 votes |
@Override public File getDirectory(String targetProject, String targetPackage) throws ShellException { if (!"MAVEN".equals(targetProject)) { return super.getDirectory(targetProject, targetPackage); } // targetProject is the output directory from the MyBatis generator // Mojo. It will be created if necessary // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be created // if it does not already exist File project = mybatisGeneratorMojo.getOutputDirectory(); if (!project.exists()) { project.mkdirs(); } if (!project.isDirectory()) { throw new ShellException(Messages.getString("Warning.9", //$NON-NLS-1$ project.getAbsolutePath())); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(Messages.getString("Warning.10", //$NON-NLS-1$ directory.getAbsolutePath())); } } return directory; }
Example #26
Source File: XmlFileMergerJaxp.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
private static String prettyPrint(Document document) throws ShellException { DomWriter dw = new DomWriter(); String s = dw.toString(document); return s; }
Example #27
Source File: DefaultShellCallback.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
public String mergeJavaFile(String newFileSource, String existingFileFullPath, String[] javadocTags, String fileEncoding) throws ShellException { throw new UnsupportedOperationException(); }
Example #28
Source File: DomWriter.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
protected void writeAnyNode(Node node) throws ShellException { // is there anything to do? if (node == null) { return; } short type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: write((DocumentType) node); break; case Node.ELEMENT_NODE: write((Element) node); break; case Node.ENTITY_REFERENCE_NODE: write((EntityReference) node); break; case Node.CDATA_SECTION_NODE: write((CDATASection) node); break; case Node.TEXT_NODE: write((Text) node); break; case Node.PROCESSING_INSTRUCTION_NODE: write((ProcessingInstruction) node); break; case Node.COMMENT_NODE: write((Comment) node); break; default: throw new ShellException(getString( "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$ } }
Example #29
Source File: MavenShellCallback.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public File getDirectory(String targetProject, String targetPackage) throws ShellException { if (!"MAVEN".equals(targetProject)) { return super.getDirectory(targetProject, targetPackage); } // targetProject is the output directory from the MyBatis generator // Mojo. It will be created if necessary // // targetPackage is interpreted as a sub directory, but in package // format (with dots instead of slashes). The sub directory will be created // if it does not already exist File project = mybatisGeneratorMojo.getOutputDirectory(); if (!project.exists()) { project.mkdirs(); } if (!project.isDirectory()) { throw new ShellException(Messages.getString("Warning.9", //$NON-NLS-1$ project.getAbsolutePath())); } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(File.separatorChar); } File directory = new File(project, sb.toString()); if (!directory.isDirectory()) { boolean rc = directory.mkdirs(); if (!rc) { throw new ShellException(Messages.getString("Warning.10", //$NON-NLS-1$ directory.getAbsolutePath())); } } return directory; }
Example #30
Source File: XmlFileMergerJaxp.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
private static String prettyPrint(Document document) throws ShellException { DomWriter dw = new DomWriter(); String s = dw.toString(document); return s; }